Skip to main content

Collections

Fixed-size arrays are created with [] literal syntax and are immutable by default:

let numbers = [1, 2, 3, 4, 5]
let strings = ["one", "two", "three"]

This is equivalent to calling the array function directly:

let numbers = array(1, 2, 3, 4, 5)
let strings = array("one", "two", "three")

A mutableArray produces a resizable, settable variant:

let items = mutableArray<i32>[10, 10]()
items[0, 0] = 100

Lists, sets, and maps​

Beyond arrays, Nylon has a standard family of collection traits, each with an immutable builder function and a mutable* counterpart:

Immutable:
List<T> list(...) : List<T>
Set<T> set(...) : Set<T>
Map<T, U> map(...) : Map<T, U>

Mutable:
MutableList<T> mutableList(...) : MutableList<T>
MutableSet<T> mutableSet(...) : MutableSet<T>
MutableMap<T, U> mutableMap(...) : MutableMap<T, U>
let names = list("Rick", "James")
let uniqueIds = set(1, 2, 3)