Module: Bluepine::Functions
- Included in:
- Attributes::Visitor, Validator
- Defined in:
- lib/bluepine/functions.rb
Overview
FP helpers
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#compose(*fns) ⇒ Object
Compose functions compose : (a -> b) -> (b -> c) -> a -> c.
-
#compose_result(*fns) ⇒ Object
A composition that early returns value f : a -> b g : a -> c.
-
#curry(method, *args) ⇒ Object
Curry instance method.
- #result(value, errors = nil) ⇒ Object
Instance Method Details
#compose(*fns) ⇒ Object
Compose functions compose : (a -> b) -> (b -> c) -> a -> c
25 26 27 28 29 30 31 |
# File 'lib/bluepine/functions.rb', line 25 def compose(*fns) ->(v) { fns.reduce(fns.shift.(v)) do |x, f| x.respond_to?(:compose) ? x.compose(f) : f.(x) end } end |
#compose_result(*fns) ⇒ Object
A composition that early returns value f : a -> b g : a -> c
36 37 38 39 40 41 42 |
# File 'lib/bluepine/functions.rb', line 36 def compose_result(*fns) ->(v) { fns.reduce(fns.shift.(v)) do |x, f| x ? x : f.(v) end } end |
#curry(method, *args) ⇒ Object
Curry instance method
45 46 47 |
# File 'lib/bluepine/functions.rb', line 45 def curry(method, *args) self.method(method).curry[*args] end |
#result(value, errors = nil) ⇒ Object
19 20 21 |
# File 'lib/bluepine/functions.rb', line 19 def result(value, errors = nil) Result.new(value, errors) end |