module Massala

Extend the Proc class to ease composition and curry usage

Public Class Methods

included(klass) click to toggle source
# File lib/lambdada/proc.rb, line 22
def self.included(klass)
  klass.send(:alias_method, :[], :massala)
end

Public Instance Methods

+(other) click to toggle source

Compose two lambdas or proc into a third one.

# File lib/lambdada/proc.rb, line 8
def +(other)
  proc { |*args| massala(*other.massala(*args) { args }) }
end
massala(*args) { |: args| ... } click to toggle source

Curry the current proc with one or several arguments. If the result of the operation is nil, return the alternate result provided in a block (if provided).

# File lib/lambdada/proc.rb, line 16
def massala(*args)
  result = arity == -1 ? call(*args) : curry[*args]
  result = block_given? ? yield : args if result.nil?
  result
end