Module: RParsec::FunctorMixin
- Defined in:
- lib/rparsec/functors.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 >> b is equivalent to b << a.
-
#compose(other) ⇒ Object
(also: #<<)
Create a Proc, when called, the parameter is first passed into other, self is called in turn with the return value from other.
-
#flip ⇒ Object
Create a Proc, which expects the two parameters in the reverse order of self.
-
#power(n) ⇒ Object
(also: #**)
Create a Proc, when called, repeatedly call self for n times.
-
#repeat(n) ⇒ Object
(also: #*)
Create a Proc, when called, repeatedly call self for n times.
-
#reverse_curry(ary = arity) ⇒ Object
Create a Proc that’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
207 208 209 |
# File 'lib/rparsec/functors.rb', line 207 def >>(other) other << self end |
#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.
198 199 200 |
# File 'lib/rparsec/functors.rb', line 198 def compose(other) Functors.compose(self, other) end |
#flip ⇒ Object
Create a Proc, which expects the two parameters in the reverse order of self.
189 190 191 |
# File 'lib/rparsec/functors.rb', line 189 def flip Functors.flip(&self) end |
#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.
274 275 276 |
# File 'lib/rparsec/functors.rb', line 274 def power(n) Functors.power(n, &self) end |
#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.
264 265 266 |
# File 'lib/rparsec/functors.rb', line 264 def repeat(n) Functors.repeat(n, &self) end |
#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.
241 242 243 |
# File 'lib/rparsec/functors.rb', line 241 def reverse_curry(ary = arity) Functors.reverse_curry(ary, &self) end |
#reverse_uncurry ⇒ Object
Uncurry a reverse curried closure.
255 256 257 |
# File 'lib/rparsec/functors.rb', line 255 def reverse_uncurry Functors.reverse_uncurry(&self) end |
#uncurry ⇒ Object
Uncurry a curried closure.
248 249 250 |
# File 'lib/rparsec/functors.rb', line 248 def uncurry Functors.uncurry(&self) end |