Method: Object#list
- Defined in:
- lib/funtools/cons.rb
#list(first, second = nil, *rest) ⇒ Object
Public: Construct a list of nested Cons cells.
first - Any Object to be the leftmost element of the list. second - Any Object to be the second element of the list (default: nil). rest - Any number of Objects to serve as elements in the list.
Returns a list (nested Cons cells).
19 20 21 22 |
# File 'lib/funtools/cons.rb', line 19 def list(first, second = nil, *rest) set = (rest.empty? && second.nil?) ? [] : rest + [nil] ([first, second] + set).reverse.reduce { |c, e| Cons.new(e, c) } end |