niva Help

Mutable List

unary

count -> Int
echo -> Unit
first -> T

last or panic, use lastOrNull for safety

last -> T
firstOrNull -> T?
lastOrNull -> T?

Immutable list, elemets will be shadow copied

toList -> List::T

Mutable list, elemets will be shadow copied

toMutableList -> MutableList::T

Like in Solitaire

shuffled -> MutableList::T

All processing methods like filter map, will execute lazy

asSequence -> Sequence::T
isEmpty -> Boolean
isNotEmpty -> Boolean
reversed -> MutableList::T

{1 2 3} sum == 6

sum -> Int
clear -> Unit

keyword

forEach: [T -> Unit] -> Unit
onEach: [T -> Unit] -> MutableList::T

{1 2 3} forEachIndexed: [i, it -> "$i element is $it" echo ]

forEachIndexed: [Int, T -> Unit] -> Unit
map: [T -> G] -> MutableList::G
mapIndexed: [Int, T -> G] -> MutableList::G
filter: [T -> Boolean] -> MutableList::T

like list[x] in C, can panic

at: Int -> T

safe version of at

atOrNull: Int -> T?

{1 2 3} contains: 1 is true

contains: T -> Unit

Returns a list containing all elements except first n elements

drop: Int -> MutableList::T

Returns a list containing all elements except last n elements.

dropLast: Int -> MutableList::T

Splits this collection into a list of lists each not exceeding the given size

chunked: Int -> List::List

{1 2 3} joinWith: ", " is 1, 2, 3

joinWith: String -> String

Usable for joining fields of objects without unpacking them, elements joining with ", "

type Person name: String {(Person name: "Bob") (Person name: "Alice")} joinTransform: [ it name ] // Bob, Alice
joinTransform: [T -> G] -> String
indexOfFirst: [T -> Boolean] -> Int
indexOfLast: [T -> Boolean] -> Int

For sorting collection of objects by one of their field

{(Person name: "Bob") (Person name: "Alice")} sortedBy: [ it name ] // {Person name: "Alice", Person name: "Bob"}
sortedBy: [T -> G] -> MutableList::T

Same as joinToString, but you can choose how to join(not only ", ")

joinWith: String transform: [T -> G] -> String

Accumulates value starting with injected value and applying operation from left to right to current accumulator value and each element(kinda fold) {1 2 3} inject: 0 into: [acc, next -> acc + next] // is 6

inject: G into: [G, T -> G] -> G

Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each elementsame as inject:into: but without accumulator arg

reduce: [T, T -> G] -> T

Splits the original collection into pair of lists, where first list contains elements for which predicate yielded true, while second list contains elements for which predicate yielded false. {1 2 3 4} partition: [it % 2 == 0] // {[2, 4], [1, 3]}

partition: [T -> Boolean] -> Pair(Sequence::T, Sequence::T)
sumOf: [T -> T] -> T

Returns the first element matching the given predicate, or null if no such element was found.

find: [T -> Boolean] -> T?

Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.

viewFrom: Int to: Int -> MutableList::T
add: T -> Boolean
addFirst: T -> Unit

Add all items from other collection

addAll: MutableList::T -> Boolean

Remove element by index

removeAt: Int -> Unit

Remove element

remove: T -> Unit

like C arr[x] = y

at: Int put: T -> Unit
Last modified: 02 November 2024