module Lab42::Stream::HigherOrder

Public Instance Methods

__combine__(op, *streams) click to toggle source
# File lib/lab42/stream/higher_order.rb, line 11
def __combine__ op, *streams
  return empty_stream if streams.any?( &:empty? )
  values = streams.map( &:head )
  new_head = op.(head, *values)
  cons_stream( new_head ){
    tail.__combine__( op, *streams.map( &:tail ) )
  }
end
combine(*streams_and_op, &operation) click to toggle source
# File lib/lab42/stream/higher_order.rb, line 5
def combine *streams_and_op, &operation
  op = streams_and_op.pop unless self.class === streams_and_op.last
  op = Behavior.make1( op, &operation )
  __combine__( op, *streams_and_op )
end
split_into(n) click to toggle source
# File lib/lab42/stream/higher_order.rb, line 20
def split_into n
  indexed = with_index
  n.times.map do | i |
    indexed
      .filter{ |_, idx| idx % n == i }
      .map( :first )
  end
end