@@ -32,6 +32,7 @@ def initialize(array)
32
32
end
33
33
34
34
# Return the number of elements in this stream.
35
+ # This is a terminal operation.
35
36
def count
36
37
@array . length
37
38
end
@@ -43,6 +44,7 @@ def count
43
44
# collected = stream.filter {|num| num % 2 == 0}.collect
44
45
# puts collected # [2, 4]
45
46
#
47
+ # This is an intermediary operation.
46
48
# +condition+:: Ruby Block taking one parameter (the stream element) and
47
49
# returning a boolean check on it.
48
50
def filter ( &condition )
@@ -60,6 +62,7 @@ def filter(&condition)
60
62
# collected = stream.map {|num| num.to_s}.collect
61
63
# puts collected # ['1', '2', '3']
62
64
#
65
+ # This is an intermediary operation.
63
66
# +function+:: Ruby Block function taking one parameter
64
67
# (the element in the stream).
65
68
def map ( &function )
@@ -71,6 +74,7 @@ def map(&function)
71
74
end
72
75
73
76
# Remove all the duplicates from the stream.
77
+ # This is an intermediary operation.
74
78
def distinct
75
79
unique = [ ]
76
80
@array . each do |val |
@@ -80,6 +84,7 @@ def distinct
80
84
end
81
85
82
86
# Skip the first n elements of the stream.
87
+ # This is an intermediary operation.
83
88
# +count+:: Number of elements to skip from the beginning of the stream.
84
89
def skip ( count )
85
90
raise ArgumentError , 'count has to be positive integer' unless count . positive? and count . is_a? Integer
@@ -92,6 +97,7 @@ def skip(count)
92
97
end
93
98
94
99
# Collect the stream's data into an array and return it.
100
+ # This is a terminal operation.
95
101
def collect
96
102
@array . dup
97
103
end
0 commit comments