Created
December 17, 2021 12:28
-
-
Save magdamiu/1a93bf45eb4b247b683027716b9c2665 to your computer and use it in GitHub Desktop.
Collections & Sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
smallList() | |
smallSequence() | |
} | |
fun smallList() = (0..5) | |
.filter { print("list filter($it) "); it % 2 == 0 } | |
.map { print("list map($it) "); it * it } | |
.first() | |
fun smallSequence() = (0..5) | |
.asSequence() | |
.filter { print("seq filter($it) "); it % 2 == 0 } | |
.map { print("seq map($it) "); it * it } | |
.first() | |
// output | |
list filter(0) list filter(1) list filter(2) list filter(3) list filter(4) list filter(5) list map(0) list map(2) list map(4) 11 ms | |
seq filter(0) seq map(0) 6 ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment