Class: Remap::Rule::Map
- Inherits:
-
Remap::Rule
- Object
- Dry::Concrete
- Remap::Rule
- Remap::Rule::Map
- Defined in:
- lib/remap/rule/map.rb
Instance Method Summary collapse
-
#adjust {|value| ... } ⇒ void
(also: #then)
Post-processor for #call.
- #call(state) ⇒ Monad::Result
- #enum(&block) ⇒ Object
- #if(&block) ⇒ Object
- #if_not(&block) ⇒ Object
- #pending(reason = "Pending mapping") ⇒ Object
Instance Method Details
#adjust {|value| ... } ⇒ void Also known as: then
This method returns an undefined value.
Post-processor for #call
61 62 63 64 65 |
# File 'lib/remap/rule/map.rb', line 61 def adjust(&block) add do |state| state.execute(&block) end end |
#call(state) ⇒ Monad::Result
34 35 36 37 38 39 40 41 42 |
# File 'lib/remap/rule/map.rb', line 34 def call(state) path.call(state) do |inner_state| rule.call(inner_state).then do |init| fn.reduce(init) do |inner, fn| fn[inner] end end end end |
#enum(&block) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/remap/rule/map.rb', line 74 def enum(&block) add do |state| state.fmap do |id, &error| Enum.call(&block).get(id, &error) end end end |
#if(&block) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/remap/rule/map.rb', line 82 def if(&block) add do |state| state.execute(&block).fmap do |bool, &error| bool ? state.value : error["#if returned false"] end end end |
#if_not(&block) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/remap/rule/map.rb', line 90 def if_not(&block) add do |state| state.execute(&block).fmap do |bool, &error| bool ? error["#if_not returned true"] : state.value end end end |
#pending(reason = "Pending mapping") ⇒ Object
68 69 70 71 72 |
# File 'lib/remap/rule/map.rb', line 68 def pending(reason = "Pending mapping") add do |state| state.problem(reason) end end |