Class: Monadist::Monad

Inherits:
Object
  • Object
show all
Defined in:
lib/monadist/monad.rb

Direct Known Subclasses

Continuation, Identity, List, Maybe

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



19
20
21
# File 'lib/monadist/monad.rb', line 19

def method_missing(*args, &block)
  fmap { |value| value.public_send *args, &block }
end

Instance Method Details

#fmap(&block) ⇒ Object



13
14
15
# File 'lib/monadist/monad.rb', line 13

def fmap(&block)
  bind { |value| self.class.unit block.call value }
end

#joinObject



4
5
6
7
8
9
# File 'lib/monadist/monad.rb', line 4

def join
  bind do |value|
    raise "Wrapped value not a monad of type #{self.class.name}" unless value.instance_of? self.class
    value
  end
end