CollectionUtils

open class CollectionUtils

Utility class to work with collections, inspired by Javascript array methods

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open fun <E> every(@NonNull collection: Collection<E>, @NonNull filter: (E) -> Boolean): Boolean
Check whether all elements of the collection pass the filter
Link copied to clipboard
open fun <E> filter(@NonNull collection: Collection<E>, @NonNull filter: (E) -> Boolean): List<E>
Returns a new Array containing only the elements which passed the filter
Link copied to clipboard
open fun <E> find(@NonNull collection: Collection<E>, @NonNull filter: (E) -> Boolean): E
Find the first element which passes the filter
Link copied to clipboard
open fun <E> findIndex(@NonNull list: List<E>, @NonNull filter: (E) -> Boolean): Int
Find the index of the first element which passes the filter
Link copied to clipboard
open fun <E> findLast(@NonNull collection: Collection<E>, @NonNull filter: (E) -> Boolean): E
Find the last element which passes the filter
Link copied to clipboard
open fun <E> findLastIndex(@NonNull list: List<E>, @NonNull filter: (E) -> Boolean): Int
Find the index of the last element which passes the filter
Link copied to clipboard
open fun <E, R> map(@NonNull collection: Collection<E>, @NonNull transform: (E) -> R): List<R>
Returns a new Array containing the results of the transform function for all elements
Link copied to clipboard
open fun <E> partition(@NonNull collection: Collection<E>, @NonNull filter: (E) -> Boolean): Pair<List<E>, List<E>>
Partition the collection into two Arrays.
Link copied to clipboard
open fun <E> removeIf(@NonNull collection: Collection<E>, @NonNull filter: (E) -> Boolean): Boolean
Removes all elements from the collection which pass the filter
Link copied to clipboard
open fun <E> some(@NonNull collection: Collection<E>, @NonNull filter: (E) -> Boolean): Boolean
Check whether any element of the collection passes the filter
Link copied to clipboard
open fun <E> splice(list: List<E>, start: Int): List<E>
Removes all elements after the specified start index
open fun <E> splice(list: List<E>, start: Int, deleteCount: Int, items: Array<E>): List<E>
Removes the specified amount of elements after the specified start index and inserts the specified items