Skip to content

Instantly share code, notes, and snippets.

@shahsurajk
Created March 22, 2020 13:22
Show Gist options
  • Save shahsurajk/44e4e7807b00a50994984a76dbd8c1a8 to your computer and use it in GitHub Desktop.
Save shahsurajk/44e4e7807b00a50994984a76dbd8c1a8 to your computer and use it in GitHub Desktop.
val colorsList = listOf("blue", "red", "black", "yellow")
val list1: List<String> = colorsList
.filter { it != "red" } // this will generate a list of size 3
val list2: List<String> = colorsList
.asSequence()
.filter { it != "red" } // so far, no processing is done and the length of the sequence is infinite!
.toList() // this is a terminal operation and will generate a list of size 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment