Module: Adt
- Included in:
- Monadt::AsyncEither, Monadt::Either, Monadt::Maybe, Monadt::ReaderStateEither
- Defined in:
- lib/monadt/adt.rb
Instance Method Summary collapse
Instance Method Details
#match(o, *cases) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/monadt/adt.rb', line 43 def match(o, *cases) m = cases.find do |tpl| tpl.klass == o.class || tpl.klass == Default end params = if m.lambda.arity > 0 o.values.take(m.lambda.arity) else [] end m.lambda.call(*params) end |
#with(klass, prc = nil, &blk) ⇒ Object
56 57 58 |
# File 'lib/monadt/adt.rb', line 56 def with(klass, prc=nil, &blk) AdtPattern.new klass, prc || blk end |