AutolangDocs
core/array

Arrays

Array is an ordered, dynamically sized list of elements laid out contiguously in memory for maximum performance. Autolang provides a rich set of Kotlin-inspired collection methods and queue operations designed for safe, deterministic orchestration pipelines.

Initialization & Type Declarations

Initialize arrays using bracket syntax [1, 2, 3] or utility helpers like listOf(), arrayOf(), and mutableListOf(). Type declarations can use the full Array<T> syntax or the shorthand T[].

// Bracket declaration with type inference val transactionIds = ["TX-101", "TX-102", "TX-103"] // Shorthand type annotation (Int[] is equivalent to Array<Int>) val scores: Int[] = [85, 92, 78] // Standard collection initializers val activeNodes = listOf("node-a", "node-b") val mutableLedger = mutableListOf<Int>(100, 250, 400) val emptyBuffer = emptyList<String>() println("Total records: " + transactionIds.size)

Indexing, Mutation & Queue Operations

Arrays support element access and assignment via bracket indexing []. Item removal distinguishes clearly between remove(value) (by value) and removeAt(index) (by index). Complete FIFO queue operations like shift() and unshift() are built-in.

val items = [10, 20, 30] // Update values by index items[0] += 5 items[1] = 99 println("Item at 0: " + items[0]) // 15 // Removal by index vs by value val removedFirst = items.removeAt(0) // Removes item at index 0, returns 15 val removedSuccess = items.remove(99) // Removes item with value 99, returns true // Queue operations (FIFO) val queue = [100, 200] queue.unshift(50) // Prepends element: [50, 100, 200] println("Front of queue: " + queue[0]) // 50 val firstOut = queue.shift() // Pops and returns first element: 50 println("Shifted element: " + firstOut) // 50 println("Queue size: " + queue.size)

Concatenation, Flattening & Predicates

Autolang supports ergonomic extensions including concat(), extend(), flat() for flattening nested structures, and condition checkers some(), every(), and findIndex().

val listA = [1, 2] val listB = [3, 4] // Concatenation returns a new array or extends in-place val combined = listA.concat(listB) println("Combined size: " + combined.size) // 4 listA.extend([10, 20]) println("Extended list size: " + listA.size) // 4 // Flatten nested arrays val nested = [[1, 2], [3, 4]] val flattened = nested.flat() println("Flattened size: " + flattened.size) // 4 println("Element at 3: " + flattened[3]) // 4 // Predicate and search tests val numbers = [10, 25, 40, 55] val hasBig = numbers.some({ x: Int -> x > 50 }) val allPositive = numbers.every({ x: Int -> x > 0 }) val targetIdx = numbers.findIndex({ x: Int -> x == 40 }) println("Has number > 50: " + hasBig) // true println("All positive: " + allPositive) // true println("Index of 40: " + targetIdx)

Functional Processing Pipelines

Transform data declaratively using operators such as map, filter, distinct, fold, scan, and flatMap without mutating the original source array.

val rawAmounts = [120, 45, 300, 15, 45, 500] // Filter and transform data val highValue = rawAmounts .filter { it >= 100 } .map<Int> { it + 10 } .distinct() println("High value count: " + highValue.size) // 3: 130, 310, 510 // Accumulate with fold and sum val totalRevenue = rawAmounts.sum() val aggregated = rawAmounts.fold(0) { acc, x -> acc + x } println("Total revenue: " + totalRevenue)

Chunking, Windowing & Pairing

Batch workflow tasks using chunked(), compute rolling calculations with windowed(), and pair arrays together using zip().

val customerBatches = ["C1", "C2", "C3", "C4", "C5"] val chunks = customerBatches.chunked(2) println("Total chunks: " + chunks.size) // 3 // Pairwise combination with zip val quantities = [2, 5, 1] val prices = [100, 20, 500] var grandTotal = 0 for ((qty, price) in quantities.zip(prices)) { grandTotal += qty * price } println("Grand total: " + grandTotal)

Multidimensional Arrays

Multidimensional arrays are nested arrays supporting chained indexing and nested in-place mutation.

val matrix: Int[][] = [ [10, 20], [30, 40] ] matrix[0][1] = 25 println("Matrix at [0][1]: " + matrix[0][1])

Method Reference

Sizing & Mutation

  • size: Int / size(): Int: Returns the number of elements in the array.
  • add(element: T): Appends an element to the end of the array.
  • remove(element: T): Bool: Finds and removes the first matching element.
  • removeAt(index: Int): T: Removes the element at the specified index and returns it.
  • shift(): T?: Removes and returns the first element of the array (returns null if empty).
  • unshift(element: T): Prepends an element to the front of the array.
  • clear(): Removes all elements from the array.

Transformations & Search

  • concat(other: Array<T>): Array<T>: Combines two arrays into a new array.
  • extend(other: Array<T>): Appends all elements from another array in-place.
  • flat(): Array<T>: Flattens one level of nested arrays.
  • count(element: T): Int: Counts occurrences of an element in the array.
  • findIndex(predicate: (T) -> Bool): Int: Returns the index of the first element satisfying the predicate (-1 if not found).
  • some(predicate: (T) -> Bool): Bool: Checks whether at least one element satisfies the predicate.
  • every(predicate: (T) -> Bool): Bool: Checks whether all elements satisfy the predicate.
  • chunked(size: Int): Array<Array<T>>: Splits the array into chunks of the given size.
  • windowed(size: Int, step: Int = 1, partialWindows: Bool = false): Array<Array<T>>: Generates sliding windows over the array.
  • zip<R>(other: Array<R>): Array<Pair<T, R>>: Pairs corresponding elements from two arrays.