Method: Immutable::Consable#zip_with
- Defined in:
- lib/immutable/consable.rb
#zip_with(*xss, &block) ⇒ Consable
Takes zero or more Consable objects and returns the Consable object obtained by applying the given block to an array of the corresponding elements of self and the input Consable objects. xs.zip_with(*yss, &block) is equivalent to xs.zip(*yss).map(&block).
303 304 305 306 307 308 309 310 311 |
# File 'lib/immutable/consable.rb', line 303 def zip_with(*xss, &block) if empty? empty else heads = xss.map { |xs| xs.null? ? nil : xs.head } tails = xss.map { |xs| xs.null? ? empty : xs.tail } Cons(yield(head, *heads), tail.zip_with(*tails, &block)) end end |