Class: Monadist::Maybe

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Monad

#fmap, #join, #method_missing

Constructor Details

#initialize(value) ⇒ Maybe

Returns a new instance of Maybe.



8
9
10
# File 'lib/monadist/maybe.rb', line 8

def initialize(value)
  @value = value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Monadist::Monad

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/monadist/maybe.rb', line 4

def value
  @value
end

Class Method Details

.unit(value) ⇒ Object



22
23
24
# File 'lib/monadist/maybe.rb', line 22

def self.unit(value)
  new value
end

Instance Method Details

#bind(&block) ⇒ Object



14
15
16
17
18
# File 'lib/monadist/maybe.rb', line 14

def bind(&block)
  return self if value.nil?

  block.call value
end