File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed
src/main/kotlin/org/athenian Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
The repo was motivated by [ this post] ( https://medium.com/@desaismital/declarative-pipelines-in-kotlin-b9e18e77f2c5 ) .
4
4
5
+ * [ Sequences and Yields] ( src/main/kotlin/org/athenian/SequencesAndYields.kt )
5
6
* [ Collection Operations] ( src/main/kotlin/org/athenian/CollectionOperations.kt )
6
7
* [ Chained Operations] ( src/main/kotlin/org/athenian/ChainedOperations.kt )
7
8
* [ Easy vs Lazy Ordering] ( src/main/kotlin/org/athenian/EvaluationOrdering.kt )
Original file line number Diff line number Diff line change @@ -10,11 +10,6 @@ fun evenNumbers(max: Int): Sequence<Int> {
10
10
}
11
11
12
12
fun main () {
13
- print (" Even numbers <= 10: " )
14
- for (i in evenNumbers(10 ))
15
- print (" $i " )
16
- println ()
17
-
18
13
print (" Even numbers <= 10: " )
19
14
evenNumbers(10 ).forEach { print (" $it " ) }
20
15
println ()
Original file line number Diff line number Diff line change
1
+ package org.athenian
2
+
3
+ fun main () {
4
+ val numbers =
5
+ sequence {
6
+ println (" one" )
7
+ yield (1 )
8
+
9
+ println (" two" )
10
+ yield (2 )
11
+
12
+ println (" three" )
13
+ yield (3 )
14
+
15
+ println (" Sequence finished..." )
16
+ }
17
+
18
+ for (n in numbers)
19
+ println (" number = $n " )
20
+ println (" Done..." )
21
+
22
+ print (" Odd numbers <= 10: " )
23
+ for (i in oddNumbers(10 ))
24
+ print (" $i " )
25
+ println ()
26
+
27
+ print (" Odd numbers <= 20: " )
28
+ for (i in oddNumbers(20 ))
29
+ print (" $i " )
30
+ println ()
31
+ }
32
+
33
+ fun oddNumbers (max : Int ): Sequence <Int > {
34
+ return sequence {
35
+ for (i in 0 .. max) {
36
+ if (i % 2 != 0 )
37
+ yield (i)
38
+ }
39
+ }
40
+ }
41
+
You can’t perform that action at this time.
0 commit comments