Wesley Acheson
12/13/2019, 2:29 PM/**
* Adds a new item to a new list, returning the new list.
* @param item the item to add to the list
* @return A new list with `item` added to the end.
*/
private fun <T> List<T>.add(item: T): List<T> {
val copy = this.toMutableList()
copy.add(item)
return copy
}
which as far as I can see creates a new array list by copying the data.ribesg
12/13/2019, 2:31 PMWesley Acheson
12/13/2019, 2:31 PMribesg
12/13/2019, 2:32 PMWesley Acheson
12/13/2019, 2:33 PMribesg
12/13/2019, 2:35 PMWesley Acheson
12/13/2019, 2:35 PMWesley Acheson
12/13/2019, 2:36 PMAdam Powell
12/13/2019, 2:42 PMMike
12/13/2019, 2:49 PM+
to create a new list that takes the first list, and a new element.
val l = listOf(1)
l + 2 // [1,2]
l.toString() // [1]
val l2 = l + 3
l2.toString() // [1, 3]
Wesley Acheson
12/13/2019, 2:58 PMMike
12/13/2019, 3:45 PMjimn
12/17/2019, 12:09 PMtypealias Vect0r<Value> = Pair< /*Size*/ () -> Int, ( /*Key*/ Int) -> Value>
val<T> Vect0r<T>.size: Int get() = first.invoke()
@JvmName("vlike_Vect0r_IntArray3")
inline operator fun <reified T> Vect0r<T>.get(index: IntArray) = this.let { (a, b) ->
index::size to { ix: Int -> b(index[ix]) }
}
jimn
12/17/2019, 12:10 PMWesley Acheson
12/18/2019, 3:26 PM