Class: Fr::Either::Left

Inherits:
Fr::Either show all
Defined in:
lib/fr/either.rb

Instance Method Summary collapse

Methods inherited from Fr::Either

bind, lefts, partition, plus, rights, unit, zero

Methods included from Monoid

#filter, #guard, #sum

Methods included from Monad

#applyM, #composeM, #filterM, #foldM, #forM, #join, #liftM, #mapM, #sequence, #unlessM, #whenM, #zipM

Methods included from Functor

#void

Constructor Details

#initialize(value) ⇒ Left

Returns a new instance of Left.



30
31
32
# File 'lib/fr/either.rb', line 30

def initialize(value)
  @value = value
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/fr/either.rb', line 51

def eql?(other)
  Either === other and
  other.fold(lambda{|o| o == @value }, lambda{|_| false })
end

#fold(left, right) ⇒ Object

Either a b -> (a -> c) -> (b -> c) -> c



35
36
37
# File 'lib/fr/either.rb', line 35

def fold(left, right)
  left.call(@value)
end

#left?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/fr/either.rb', line 47

def left?
  true
end

#map(&f) ⇒ Object



39
40
41
# File 'lib/fr/either.rb', line 39

def map(&f)
  self
end

#right?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/fr/either.rb', line 43

def right?
  false
end