Class: Ruff::Standard::State::Instance
- Inherits:
-
Object
- Object
- Ruff::Standard::State::Instance
- Defined in:
- lib/ruff/standard/state.rb
Instance Attribute Summary collapse
-
#eff ⇒ Object
readonly
You can reimplement the handler using these effect instances with accessing
#eff.get
and#eff.modify
.
Instance Method Summary collapse
-
#get ⇒ S
is a smart method to invoke the effect operation
State.get
. -
#initialize ⇒ Instance
constructor
makes new instances.
-
#modify(&fn) ⇒ ()
is a smart hetmod to invoke the effect operation
State.modify
. -
#put(s) ⇒ ()
is a short hand for
modify {|_| s }
. -
#with(&th) ⇒ A!{e}
is a short hand for
with_init(nil, th)
. -
#with_init(init, &th) ⇒ A!{e}
is a handler to interpret the effect invocations like state monad .
Constructor Details
Instance Attribute Details
#eff ⇒ Object (readonly)
You can reimplement the handler using these effect instances
with accessing #eff.get
and #eff.modify
.
101 102 103 |
# File 'lib/ruff/standard/state.rb', line 101 def eff @eff end |
Instance Method Details
#get ⇒ S
is a smart method to invoke the effect operation State.get
.
40 41 42 |
# File 'lib/ruff/standard/state.rb', line 40 def get @eff.get.perform end |
#modify(&fn) ⇒ ()
is a smart hetmod to invoke the effect operation State.modify
.
49 50 51 |
# File 'lib/ruff/standard/state.rb', line 49 def modify(&fn) @eff.modify.perform fn end |
#put(s) ⇒ ()
is a short hand for modify {|_| s }
57 58 59 |
# File 'lib/ruff/standard/state.rb', line 57 def put(s) @eff.modify.perform ->(_) { s } end |
#with(&th) ⇒ A!{e}
is a short hand for with_init(nil, th)
.
95 96 97 |
# File 'lib/ruff/standard/state.rb', line 95 def with(&th) with_init(nil, &th) end |
#with_init(init, &th) ⇒ A!{e}
is a handler to interpret the effect invocations like state monad .
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruff/standard/state.rb', line 71 def with_init(init, &th) # not a parameter passing style, or so-called *pure* implementation, # just using mutable assignment state = init # The handler *closes* `state` variable so it should be created every time. Ruff.handler .on(@eff.modify) do |k, fn| state = fn[state] k[nil] end.on(@eff.get) do |k| k[state] end .run(&th) end |