Skip to content

Instantly share code, notes, and snippets.

@MarcinMoskala
Created September 16, 2019 11:19
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 MarcinMoskala/d7d5caddf3b7d2007037995a6d95508a to your computer and use it in GitHub Desktop.
Save MarcinMoskala/d7d5caddf3b7d2007037995a6d95508a to your computer and use it in GitHub Desktop.
public inline fun <T> List(
size: Int,
init: (index: Int) -> T
): List<T> = MutableList(size, init)
public inline fun <T> MutableList(
size: Int,
init: (index: Int) -> T
): MutableList<T> {
val list = ArrayList<T>(size)
repeat(size) { index -> list.add(init(index)) }
return list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment