Module: Dry::Monads::Transformer
Instance Method Summary collapse
-
#fmap2(*args) ⇒ Object
Lifts a block/proc over the 2-level nested structure.
-
#fmap3(*args) ⇒ Object
Lifts a block/proc over the 3-level nested structure.
Instance Method Details
#fmap2(*args) ⇒ Object
Lifts a block/proc over the 2-level nested structure. This is essentially fmap . fmap (. is the function composition operator from Haskell) or the functor instance for a two-level monadic structure like List Either.
15 16 17 18 19 20 21 22 |
# File 'lib/dry/monads/transformer.rb', line 15 def fmap2(*args) if block_given? fmap { |a| a.fmap { |b| yield(b, *args) } } else func, *rest = args fmap { |a| a.fmap { |b| func.(b, *rest) } } end end |
#fmap3(*args) ⇒ Object
Lifts a block/proc over the 3-level nested structure.
32 33 34 35 36 37 38 39 |
# File 'lib/dry/monads/transformer.rb', line 32 def fmap3(*args) if block_given? fmap { |a| a.fmap { |b| b.fmap { |c| yield(c, *args) } } } else func, *rest = args fmap { |a| a.fmap { |b| b.fmap { |c| func.(c, *rest) } } } end end |