Skip to content

Instantly share code, notes, and snippets.

@shahsurajk
Last active March 22, 2020 13:11
Show Gist options
  • Save shahsurajk/44693931ece956ad6cd0c01ccb9bbbb1 to your computer and use it in GitHub Desktop.
Save shahsurajk/44693931ece956ad6cd0c01ccb9bbbb1 to your computer and use it in GitHub Desktop.
val colorsList = listOf("blue", "red", "black", "yellow")
val list1: List<String> = colorsList
.filter { it != "red" } // new array list of size 3
.map { it.toLowerCase() } // new array list of size 4
.take(2) // new array list of size 2
val list2: List<String> = colorsList
.asSequence()
.filter { it != "red" } // will run and take "blue" and "black"
.map { it.toLowerCase()} // new array list of default size
.take(2) // will run 3 iterations and then exit with just one array instance
.toList()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment