Sha256: dc4a2eeb087daaeeea272f37c89ce45ede5160dcca7c42101aaae568ef21e5cb

Contents?: true

Size: 649 Bytes

Versions: 6

Compression:

Stored size: 649 Bytes

Contents

class Proc

  # Convert a Proc object into new partial Proc object.
  #
  #   a = proc { |a,b,c| a+b+c }
  #   b = a.partial(X,2,X)
  #   b[1,3] #=> 6
  #
  #   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

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

end

# X class is used to represent an argument "slot".

class X < ArgumentError
end

# Convenience method for an argument slot.
# It simple returns the X exception class.

def __
  X
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-2.8.4 lib/more/facets/partial.rb
facets-2.8.3 lib/more/facets/partial.rb
facets-2.8.2 lib/more/facets/partial.rb
facets-2.8.1 lib/more/facets/partial.rb
facets-2.8.0 lib/more/facets/partial.rb
facets-2.7.0 lib/more/facets/partial.rb