Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created November 16, 2021 16:29
Show Gist options
  • Save EmmanuelGuther/681096d24d4162a9b7b8d731bf2fe6cb to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/681096d24d4162a9b7b8d731bf2fe6cb to your computer and use it in GitHub Desktop.
kotlin collections build-list
For those cases where you have to calculate the elements before adding them to the list,
you "save" the boilerplate of creating a mutable list and then returning an immutable list.
The example of the docs is... but it is understood where it goes.
val y = buildList () {
add ('a')
addAll (x)
add ('d')
}
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/build-list.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment