Module: LambdaDriver::WithArgs

Included in:
Method, Proc, Symbol
Defined in:
lib/lambda_driver/with_args.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



21
22
23
# File 'lib/lambda_driver/with_args.rb', line 21

def self.included(klass)
  klass.send(:alias_method, :*,  :with_args)
end

Instance Method Details

#with_args(*args) ⇒ Object

Returns partially applied function that has 2nd and more parameters fixed by given *args.

f = lambda{|x, y, z| [x, y, z]}
h = f.with_args(:a, :b)
h.(:c) # => [:c, :a, :b]

This method is aliased as ‘*`.

f * :foo  # => f.with_args(:foo)


15
16
17
18
19
# File 'lib/lambda_driver/with_args.rb', line 15

def with_args(*args)
  lambda{|v|
    self.to_proc.call(*([v] + args))
  }
end