Class: Kleisli::Maybe

Inherits:
Monad show all
Defined in:
lib/kleisli/maybe.rb

Direct Known Subclasses

None, Some

Defined Under Namespace

Classes: None, Some

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Monad

#>, #>>

Methods inherited from Functor

#fmap

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/kleisli/maybe.rb', line 5

def value
  @value
end

Class Method Details

.lift(value) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/kleisli/maybe.rb', line 7

def self.lift(value)
  if value.nil?
    None.new
  else
    Some.new(value)
  end
end

Instance Method Details

#*(other) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/kleisli/maybe.rb', line 19

def *(other)
  self >-> f {
    f = f.to_proc
    other >-> val {
      Maybe.lift(f.arity > 1 ? f.curry.call(val) : f.call(val))
    }
  }
end

#==(other) ⇒ Object



15
16
17
# File 'lib/kleisli/maybe.rb', line 15

def ==(other)
  value == other.value
end