class Obfusk::Monads::State
Public Class Methods
bind_pass(m, &b)
click to toggle source
# File lib/obfusk/monads.rb, line 131 def self.bind_pass(m, &b) state { |s| x = m.run[s]; b[x.value].run[x.state] } end
eval(m, s)
click to toggle source
evaluate response with the given initial state and return the final value, discarding the final state
# File lib/obfusk/monads.rb, line 91 def self.eval(m, s) m.run[s].value end
exec(m, s)
click to toggle source
evaluate response with the given initial state and return the final state, discarding the final value
# File lib/obfusk/monads.rb, line 97 def self.exec(m, s) m.run[s].state end
get()
click to toggle source
get the state
# File lib/obfusk/monads.rb, line 108 def self.get state { |s| Pair s, s } end
gets(f = nil, &b)
click to toggle source
get a specific component of the state, using a projection function (or block)
# File lib/obfusk/monads.rb, line 124 def self.gets(f = nil, &b) state { |s| Pair (f || b)[s], s } end
modify(f = nil, &b)
click to toggle source
modify the state by applying a function (or block)
# File lib/obfusk/monads.rb, line 118 def self.modify(f = nil, &b) state { |s| Pair nil, (f || b)[s] } end
mreturn(x)
click to toggle source
# File lib/obfusk/monads.rb, line 128 def self.mreturn(x) state { |s| Pair x, s } end
put(s)
click to toggle source
set the state
# File lib/obfusk/monads.rb, line 113 def self.put(s) state { |_| Pair nil, s } end
state(f = nil, &b)
click to toggle source
construct a state monad computation from a function (or block)
# File lib/obfusk/monads.rb, line 85 def self.state(f = nil, &b) State f || b end
with(m, f = nil, &b)
click to toggle source
execute action on a state modified by applying a function (or block)
# File lib/obfusk/monads.rb, line 103 def self.with(m, f = nil, &b) state { |s| m.run[(f || b)[s]] } end