Sha256: 187f3faf97cf29f2154bd08f866f5eb840b6ea71cf966ca693ed334b45bb955e

Contents?: true

Size: 519 Bytes

Versions: 1

Compression:

Stored size: 519 Bytes

Contents

# -*- encoding : utf-8 -*-
module LambdaDriver::WithArgs

  # 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)
  #
  def with_args(*args)
    lambda{|v|
      self.to_proc.call(*([v] + args))
    }
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lambda_driver-1.3.0 lib/lambda_driver/with_args.rb