Module: Invokable::Compose

Included in:
Core, Method, Proc
Defined in:
lib/invokable/compose.rb

Overview

Note:

This module should not be used directly.

The #<< and #>> methods for right and left function composition.

This module is included in the Invokable module and the Proc and Method classes when used with versions of Ruby earlier than 2.6 (when they were added).

Instance Method Summary collapse

Instance Method Details

#<<(invokable) ⇒ Proc

Return a proc that is the composition of this invokable and the given invokable. The returned proc takes a variable number of arguments, calls invokable with them then calls this proc with the result.

Returns:



14
15
16
17
18
# File 'lib/invokable/compose.rb', line 14

def <<(invokable)
  lambda do |*args|
    call(Invokable.coerce(invokable).call(*args))
  end
end

#>>(invokable) ⇒ Proc

Return a proc that is the composition of this invokable and the given invokable. The returned proc takes a variable number of arguments, calls invokable with them then calls this proc with the result.

Returns:



25
26
27
28
29
# File 'lib/invokable/compose.rb', line 25

def >>(invokable)
  lambda do |*args|
    Invokable.coerce(invokable).call(call(*args))
  end
end