Stdlib index
- Captured-borrow migration worklist (3.3.3)
- Owned-bind migration worklist (8.2.7)
- Return-side title audit — the ride-through enumeration
- stdlib ownership audit
- stdlib ownership dispositions (plan 1.3.1 / 4.3.1)
aot
codec
codec / csv
codec / json
collection
- ArrayList
- BPlusTree
- Cache
- Collectors
- HashMap
- HashSet
- Heap
- ImmutableList
- ImmutableMap
- ImmutableSet
- LinkedList
- RedBlackTree
- Sort
collection / ltm
concurrent
error
- Exception
- NoOptionalValueException
- NotProvidedException
- RecoverableException
- ScopedBuildFailedException
- ScopeNotActiveException
- Throwable
- UnrecoverableException
gfx
hash
ifx
io
io / file
io / net
io / net / dns
io / net / uri
lang
lang / stream
math
math / fft
math / linalg
math / npio
math / poly
math / random
math / stats
nucleo
- Columns — the Arrow-laid-out substrate
- Fused tensor expressions — Fuse
- Table — the lazy, typed dataframe
- Tape — define-by-run autograd
- Transform intrinsics — Grad, Vmap, Jit
process
reflect
search / distance
search / fuzzy
search / ngram
session
time
- Clock
- DateTimeFormatter
- Duration
- Instant
- LocalDate
- LocalDateTime
- LocalTime
- Period
- ZonedDateTime
- ZoneId
- ZoneOffset
wire
xpu
xpu / mesh
ImmutableList<T>
cajeta.collection.ImmutableList — immutable, array-backed list: a frozen
snapshot of an ArrayList. The backing array is copied once at construction
and never mutated, so reads are O(1) and the structure is safe to share
without defensive copies. There are no mutators; to “change” one, build a new
list from a fresh ArrayList. Like ArrayList, get returns the type’s zero
value on an out-of-range index rather than throwing.
ArrayList<int32> src = heap ArrayList<int32>();
src.add(10);
src.add(20);
src.add(30);
// Freeze it. The `#` surrenders `src`, whose elements move into the snapshot.
ImmutableList<int32> frozen = heap ImmutableList<int32>(#src);
int64 n = frozen.count(); // 3
int32 second = frozen.get(1); // 20
int32 at = frozen.indexOf(30); // 2
boolean has = frozen.contains(40); // false
Methods
| Signature | |
|---|---|
ImmutableList(#ArrayList<T> src) ⚑ | Build an immutable copy of src, which is consumed, so the call must write #src |
int64 count() | Number of elements |
boolean isEmpty() | count() == 0 |
T get(int32 i) | Element at i (0-based), or the type’s zero value if out of range |
boolean contains(T v) | True iff some element is ==-equal to v; O(n) |
int32 indexOf(T v) | Index of the first ==-equal element, or -1 if none; O(n) |
#ArrayStream<T> stream() | Heap-allocated ArrayStream walking all elements in order |
⚑ = @EntryPoint
See also
- Tour: ImmutableListDemo
- Source:
runtime/src/cajeta/collection/ImmutableList.cajeta - ArrayList — the mutable source
- ImmutableSet, ImmutableMap — the other frozen collections