Class: Decoding::Decoders::Map
- Inherits:
-
Decoding::Decoder
- Object
- Decoding::Decoder
- Decoding::Decoders::Map
- Defined in:
- lib/decoding/decoders/map.rb
Overview
A decoder that decodes a value and then applies a transformation to it, if successful.
Instance Method Summary collapse
- #call(value) ⇒ Decoding::Result<b>
-
#initialize(decoder, *rest) {|value| ... } ⇒ Map
constructor
A new instance of Map.
Methods inherited from Decoding::Decoder
Constructor Details
#initialize(decoder, *rest) {|value| ... } ⇒ Map
Returns a new instance of Map.
15 16 17 18 19 |
# File 'lib/decoding/decoders/map.rb', line 15 def initialize(decoder, *rest, &block) @decoders = [decoder, *rest].map(&:to_decoder) @block = block super() end |
Instance Method Details
#call(value) ⇒ Decoding::Result<b>
23 24 25 26 27 |
# File 'lib/decoding/decoders/map.rb', line 23 def call(value) Result .all(@decoders.map { _1.call(value) }) .map { @block.call(*_1) } end |