Class: TAlgebra::Monad::List

Inherits:
Object
  • Object
show all
Includes:
TAlgebra::Monad
Defined in:
lib/t_algebra/monad/list.rb

Instance Method Summary collapse

Methods included from TAlgebra::Monad

included

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/t_algebra/monad/list.rb', line 28

def ==(other)
  from_list == other.from_list
end

#bind(&block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/t_algebra/monad/list.rb', line 16

def bind(&block)
  self.class.pure(
    *values.reduce([]) do |acc, l|
      acc.concat(block.call(l).send(:values))
    end
  )
end

#fmap(&block) ⇒ Object



10
11
12
13
14
# File 'lib/t_algebra/monad/list.rb', line 10

def fmap(&block)
  self.class.pure(
    *values.map { |l| yield(l) }
  )
end

#from_listObject



24
25
26
# File 'lib/t_algebra/monad/list.rb', line 24

def from_list
  values
end