File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -140,27 +140,27 @@ Stream.randint(1, 100).limit(100).toList()
140140
141141* Print the numbers from 1 to 100
142142``` py
143- Stream.iterate( 1 , lambda i : i + 1 ).limit(100 ).forEach(print )
143+ Stream.integers( ).limit(100 ).forEach(print )
144144```
145145
146- * Generate a list of squares of the number from 1 to 100
146+ * Generate a list made of zeros with a length of 10
147147``` py
148- Stream.iterate( 1 , lambda i : i + 1 ).map( lambda x : x ** 2 ). limit(100 ).toList()
148+ Stream.constant( 0 ). limit(10 ).toList()
149149```
150150
151- * Generate a list of 0 with a lenght of 100
151+ * Generate a list of squares of the number from 1 to 20
152152``` py
153- Stream.generate( lambda : 0 ).limit(100 ).toList()
153+ IntStream.integers().map( lambda x : x ** 2 ).limit(20 ).toList()
154154```
155155
156156* Generate a set of the first 100 odds number
157157``` py
158- Stream .odds().limit(100 ).toSet()
158+ IntStream .odds().limit(100 ).toSet()
159159```
160160
161- * Generate a list of all the primes number smaller than 100
161+ * Generate a list of all the primes number smaller than 1000
162162``` py
163- Stream.primes().takeWhile(lambda x : x < 100 ).toList()
163+ Stream.primes().takeWhile(lambda x : x < 1000 ).toList()
164164```
165165
166166
Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ def concat(*streams):
9797 '''
9898 return Stream (IteratorUtils .concat (* streams ))
9999
100+ @staticmethod
101+ def constant (element ):
102+
103+ return Stream .generate (lambda : element )
104+
100105 @staticmethod
101106 def booleans ():
102107 return Stream .generate (lambda : random .randint (0 , 1 ) == 1 )
You can’t perform that action at this time.
0 commit comments