Module: Elixir::Stream

Defined in:
lib/elixir/stream.rb

Constant Summary collapse

INFINITY =
::Float::INFINITY

Class Method Summary collapse

Class Method Details

.cycle(collection) ⇒ Object



7
8
9
# File 'lib/elixir/stream.rb', line 7

def cycle collection
  collection.cycle
end

.interval(milliseconds) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/elixir/stream.rb', line 11

def interval milliseconds
  Enumerator.new INFINITY do |yielder|
    0.upto INFINITY do |n|
      sleep milliseconds.fdiv 1000
      yielder << n
    end
  end
end

.iterate(value) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/elixir/stream.rb', line 20

def iterate value
  Enumerator.new INFINITY do |yielder|
    loop do
      yielder << value
      value = yield value
    end
  end
end

.repeatedlyObject



29
30
31
32
33
34
35
# File 'lib/elixir/stream.rb', line 29

def repeatedly
  Enumerator.new INFINITY do |yielder|
    loop do
      yielder << yield
    end
  end
end

.timer(milliseconds) ⇒ Object



37
38
39
40
41
42
# File 'lib/elixir/stream.rb', line 37

def timer milliseconds
  Enumerator.new 1 do |yielder|
    sleep milliseconds.fdiv 1000
    yielder << 0
  end
end

.unfold(tuple) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/elixir/stream.rb', line 44

def unfold tuple
  Enumerator.new INFINITY do |yielder|
    loop do
      value, tuple = yield tuple
      yielder << value
    end
  end
end