Module: RParsec::FunctorMixin
- Defined in:
- lib/rparsec/functor_mixin.rb
Overview
This module provides instance methods that manipulate closures in a functional style. It is typically included in Proc and Method.
Instance Method Summary collapse
-
#>>(other) ⇒ Object
a >> bis equivalent tob << a. -
#compose(other) ⇒ Object
(also: #<<)
Create a
Proc, when called, the parameter is first passed intoother,selfis called in turn with the return value fromother. -
#flip ⇒ Object
Create a
Proc, which expects the two parameters in the reverse order ofself. -
#power(n) ⇒ Object
(also: #**)
Create a
Proc, when called, repeatedly callselfforntimes. -
#repeat(n) ⇒ Object
(also: #*)
Create a
Proc, when called, repeatedly callselfforntimes. -
#reverse_curry(ary = arity) ⇒ Object
Create a
Procthat’s curriable. -
#reverse_uncurry ⇒ Object
Uncurry a reverse curried closure.
-
#uncurry ⇒ Object
Uncurry a curried closure.
Instance Method Details
#>>(other) ⇒ Object
a >> b is equivalent to b << a. See also #<<.
25 |
# File 'lib/rparsec/functor_mixin.rb', line 25 def >>(other) = other << self |
#compose(other) ⇒ Object Also known as: <<
Create a Proc, when called, the parameter is first passed into other, self is called in turn with the return value from other.
19 |
# File 'lib/rparsec/functor_mixin.rb', line 19 def compose(other) = Functors.compose(self, other) |
#flip ⇒ Object
Create a Proc, which expects the two parameters in the reverse order of self.
12 |
# File 'lib/rparsec/functor_mixin.rb', line 12 def flip = Functors.flip(&self) |
#power(n) ⇒ Object Also known as: **
Create a Proc, when called, repeatedly call self for n times. At each iteration, return value from the previous iteration is used as parameter.
78 |
# File 'lib/rparsec/functor_mixin.rb', line 78 def power(n) = Functors.power(n, &self) |
#repeat(n) ⇒ Object Also known as: *
Create a Proc, when called, repeatedly call self for n times. The same arguments are passed to each invocation.
71 |
# File 'lib/rparsec/functor_mixin.rb', line 71 def repeat(n) = Functors.repeat(n, &self) |
#reverse_curry(ary = arity) ⇒ Object
Create a Proc that’s curriable. When curried, parameters are passed in from right to left. i.e. closure.reverse_curry.call(a).call(b) is quivalent to closure.call(b, a). self is encapsulated under the hood to perform the actual job when currying is done. ary explicitly specifies the number of parameters to curry.
55 |
# File 'lib/rparsec/functor_mixin.rb', line 55 def reverse_curry(ary = arity) = Functors.reverse_curry(ary, &self) |
#reverse_uncurry ⇒ Object
Uncurry a reverse curried closure.
65 |
# File 'lib/rparsec/functor_mixin.rb', line 65 def reverse_uncurry = Functors.reverse_uncurry(&self) |
#uncurry ⇒ Object
Uncurry a curried closure.
60 |
# File 'lib/rparsec/functor_mixin.rb', line 60 def uncurry = Functors.uncurry(&self) |