Module: Mayak::Csv::Decoder

Extended by:
T::Generic, T::Sig
Included in:
FromFunction, HashDecoder, HashDecoderStrict
Defined in:
lib/mayak/csv/decoder.rb

Defined Under Namespace

Classes: FromFunction, HashDecoder, HashDecoderStrict

Constant Summary collapse

Value =
type_member

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hash_decoder(separator: ",") ⇒ Object



56
57
58
# File 'lib/mayak/csv/decoder.rb', line 56

def self.hash_decoder(separator: ",")
  HashDecoder.new(separator: separator)
end

.hash_decoder_strict(separator: ",") ⇒ Object



51
52
53
# File 'lib/mayak/csv/decoder.rb', line 51

def self.hash_decoder_strict(separator: ",")
  HashDecoderStrict.new(separator: separator)
end

Instance Method Details

#decode(csv) ⇒ Object



19
20
# File 'lib/mayak/csv/decoder.rb', line 19

def decode(csv)
end

#map(&blk) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/mayak/csv/decoder.rb', line 27

def map(&blk)
  ::Mayak::Csv::Decoder::FromFunction[T.type_parameter(:NewValue)].new(fn: -> (csv) do
    decode(csv).map do |values|
      values.map { |value| blk.call(value) }
    end
  end)
end

#map_try(&blk) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/mayak/csv/decoder.rb', line 40

def map_try(&blk)
  ::Mayak::Csv::Decoder::FromFunction[T.type_parameter(:NewValue)].new(fn: -> (csv) do
    decode(csv).flat_map do |values|
      Mayak::Monads::Try.sequence(
        values.map { |value| blk.call(value) }
      )
    end
  end)
end