-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoreEvaluationOrdering.kt
45 lines (39 loc) · 1.3 KB
/
MoreEvaluationOrdering.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package org.athenian
fun main() {
data class Person(val name: String, val age: Int)
val people = listOf(
Person("Chris martin", 31),
Person("Will champion", 32),
Person("Johny buckland", 33),
Person("Guy berryman", 34),
Person("Mhris cartin", 30)
)
println(
"Eager eval: " +
people
.filter { it.age > 30 }
.onEach { println("First map evaluating $it") }
.map {
it.name
.split(" ")
.map { name -> name[0] }
.joinToString("")
}
.onEach { println("Second map evaluating $it") }
.map { it.uppercase() })
println("Lazy eval: " +
people
.asSequence()
.filter { it.age > 30 }
.onEach { println("First map evaluating $it") }
.map {
it.name
.split(" ")
.map { name -> name[0] }
.joinToString("")
}
.onEach { println("Second map evaluating $it") }
.map { it.uppercase() }
.toList()
)
}