Skip to content

Commit 9a3facd

Browse files
authored
Update README.md
1 parent 3df6a42 commit 9a3facd

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ operations to modify and/or get information about the collection. The operations
1414
* **Intermediate** operations (skip, filter, map etc) -- operations which are altering the Stream and still leave it open for further modifications.
1515
* **Terminal** operations (count, collect etc) -- operations which are executed after all the modifications have been done and are returning a finite result.
1616

17-
First glance (finite Stream from an array):
17+
First glance:
18+
19+
1) **Finite** Stream from an array:
1820

1921
```ruby
2022
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
@@ -26,7 +28,17 @@ collected = stream
2628
puts collected # [6, 8, 10]
2729
```
2830

29-
More examples soon.
31+
2) Generate a (potentially) **infinite** stream:
32+
33+
```ruby
34+
stream = Stream.generate(150) { &seed }
35+
```
36+
37+
The ``generate`` method takes a ``limit`` (max number of elements) and a ``&seed`` Block function which
38+
returns a new element at each ``seed.call``. A limit is necessary as, without it, this Stream would be infinite.
39+
If no limit is specified, the default is ``100`` elements.
40+
41+
This mechanism is useful, for instance, when you have to consume an incomming stream of objects from some ``IO`` objects.
3042

3143
## Installation
3244

0 commit comments

Comments
 (0)