Multik 0.3.0 Help

Universal operations

Overview

Universal operations are extension functions on MultiArray<T, D> that follow Kotlin collection conventions. They provide familiar APIs for transforming, filtering, aggregating, and converting arrays.

Predicates

Function

Description

all

true if all elements match a predicate.

any

true if at least one element matches.

contains

true if the array contains a given element.

Traversal

Function

Description

forEach

Apply an action to each element.

onEach

Apply an action to each element and return the array.

Transformation

Function

Description

map

Transform each element, preserving shape.

flatMap

Transform each element into an iterable, flatten to 1D.

scan

Running accumulation, returning all intermediate values.

append

Append elements or another array.

repeat

Tile elements n times into a flat 1D array.

clip

Clamp every element to a min..max range.

Filtering

Function

Description

filter

Elements matching a predicate, returned as 1D.

find

First element matching a predicate, or null.

distinct

Unique elements as a 1D array.

Aggregation

Function

Description

fold

Accumulate from an initial value.

reduce

Accumulate without an initial value.

sum

Sum of all elements.

average

Average of all elements.

count

Count elements, optionally matching a predicate.

max

Largest element, or null if empty.

min

Smallest element, or null if empty.

maximum

Element-wise maximum of two arrays.

minimum

Element-wise minimum of two arrays.

Function

Description

first

First element, or first matching a predicate.

last

Last element, or last matching a predicate.

indexOf

Flat index of the first occurrence, or -1.

Ordering

Function

Description

sorted

New array with elements sorted.

reversed

New array with elements in reverse order.

Partitioning

Function

Description

partition

Split into (matching, non-matching) pair.

chunked

Split into fixed-size chunks as a 2D array.

windowed

Sliding window as a 2D array.

drop

Drop the first n elements (1D only).

Grouping

Function

Description

groupNDArray

Group elements by key into a map of 1D arrays.

associate

Build a map from key-value pairs.

intersect

Set intersection with another collection.

Conversion

Function

Description

toList

Flat List<T> of all elements.

toCollection

Append all elements to a mutable collection.

toPrimitiveArray

Convert to a Kotlin primitive array.

toArray

Convert to nested Kotlin arrays.

asSequence

Lazy Sequence<T> over elements.

toType

Convert element type (e.g. Int to Double).

joinTo

Build a string representation.

28 February 2026