Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created December 17, 2021 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/1a93bf45eb4b247b683027716b9c2665 to your computer and use it in GitHub Desktop.
Save magdamiu/1a93bf45eb4b247b683027716b9c2665 to your computer and use it in GitHub Desktop.
Collections & Sequences
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