Class: Lab42::Stream::Empty

Inherits:
Lab42::Stream show all
Defined in:
lib/lab42/stream/empty.rb

Constant Summary

Constants inherited from Lab42::Stream

ConstraintError, Version

Instance Attribute Summary

Attributes inherited from Lab42::Stream

#promise

Instance Method Summary collapse

Methods inherited from Lab42::Stream

#__inject_while__, #drop, #each, #filter_by_proc, #reduce_while, #to_stream, #transform_by_proc

Methods included from Enumerable

#to_stream

Instance Method Details

#__flatmap__(a_proc) ⇒ Object



27
# File 'lib/lab42/stream/empty.rb', line 27

def __flatmap__ a_proc; self end

#append(other) ⇒ Object Also known as: +

TODO: Implement all self returning methods with Forwarder

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/lab42/stream/empty.rb', line 5

def append other
  raise ArgumentError, "not a stream #{other}" unless self.class.superclass === other
  # ??? Is the to_stream message a good idea
  other.to_stream
end

#empty?Boolean

Returns:

  • (Boolean)


12
# File 'lib/lab42/stream/empty.rb', line 12

def empty?; true end

#filter(*args, &blk) ⇒ Object



14
# File 'lib/lab42/stream/empty.rb', line 14

def filter *args, &blk; self end

#flatmap(*args, &blk) ⇒ Object



26
# File 'lib/lab42/stream/empty.rb', line 26

def flatmap *args, &blk; self end

#headObject

Raises:

  • (StopIteration)


16
# File 'lib/lab42/stream/empty.rb', line 16

def head; raise StopIteration, "head called on empty stream" end

#make_cyclicObject



18
# File 'lib/lab42/stream/empty.rb', line 18

def make_cyclic; self end

#map(*args, &blk) ⇒ Object



19
# File 'lib/lab42/stream/empty.rb', line 19

def map *args, &blk; self end

#tailObject

I believe that this definition is sound, although it is an obvious pitfall But falling into it once, means understanding streams better, well that is my opinion now, we will see what promises the future will bring…



23
# File 'lib/lab42/stream/empty.rb', line 23

def tail; self end