Sha256: 9e35202c59d02516aec0eef5f74ae2225daef0ab6e4cd1b32169ace2bed888ab

Contents?: true

Size: 734 Bytes

Versions: 11

Compression:

Stored size: 734 Bytes

Contents

# MissingArgument exception class is used to represent an argument "hole".

class MissingArgument < ArgumentError
end

# Convenience method for an argument hole.
# It simple returns the MissingArgument exception class.

def __
  MissingArgument
end

class Proc

  # Convert a Proc object into new partial Proc object.
  #
  #   a = proc { |a,b,c| a+b+c }
  #   b = a.partial(__, 2, __)
  #   b[1,3] #=> 6
  #
  # This method is similar to Proc#curry.
  #
  # CREDT Trans
  #
  # TODO: Parhaps ArgumentError would suffice, and we don't need MissingArgument?

  def partial(*args)
    Proc.new do |*spice|
      result = args.collect do |a|
        MissingArgument == a ? spice.pop : a
      end
      call(*result)
    end
  end

end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
facets-2.6.0 lib/more/facets/partial.rb
facets-2.4.0 lib/facets/proc/partial.rb
facets-2.4.1 lib/facets/proc/partial.rb
facets-2.4.4 lib/more/facets/partial.rb
facets-2.4.2 lib/core/facets/proc/partial.rb
facets-2.4.3 lib/more/facets/partial.rb
facets-2.4.5 lib/more/facets/partial.rb
facets-2.5.0 lib/more/facets/partial.rb
facets-2.5.1 lib/more/facets/partial.rb
facets-2.5.2 lib/more/facets/partial.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/more/facets/partial.rb