kbox-jvm / ch.tutteli.kbox / kotlin.Array

Extensions for kotlin.Array

appendToStringBuilder

fun <T> Array<T>.appendToStringBuilder(sb: StringBuilder, separator: String, append: (it: T) -> Unit): Unit

Appends all elements of this list to the given sb by calling append and separates the elements with the given separator.

fun <T> Array<T>.appendToStringBuilder(sb: StringBuilder, separator: String, lastSeparator: String, append: (it: T) -> Unit): Unit

Appends all elements of this list to the given sb by calling append and separates the elements with the given separator whereas lastSeparator is used to separate the last and the second last element.

ifWithinBound

fun <E, R> Array<E>.ifWithinBound(index: Int, thenBlock: () -> R, elseBlock: () -> R): R

Checks if the given index is within the bound of this List (index < List.size) and correspondingly executes the thenBlock or the elseBlock.

joinToString

fun <T> Array<T>.joinToString(separator: String, append: (it: T, StringBuilder) -> Unit): String

Joins all elements of this list by calling append and separates the elements with the given separator.

fun <T> Array<T>.joinToString(separator: String, lastSeparator: String, append: (it: T, StringBuilder) -> Unit): String

Joins all elements of this list by calling append and separates the elements with the given separator whereas lastSeparator is used to separate the last and the second last element.

mapWithIndex

fun <T> Array<T>.mapWithIndex(): List<WithIndex<T>>

Maps the values to WithIndex, containing the index next to the value itself.