Bootstrapping definitions about arrays #
This file contains some definitions in Array
needed for Std.List.Basic
.
Turns #[a, b]
into #[(a, 0), (b, 1)]
.
Equations
- Array.zipWithIndex arr = Array.mapIdx arr fun (i : Fin (Array.size arr)) (a : α) => (a, i.val)
Instances For
@[inline]
Like as.toList ++ l
, but in a single pass.
Equations
- Array.toListAppend as l = Array.foldr List.cons l as (Array.size as)
Instances For
ofFn f
with f : Fin n → α
returns the list whose ith element is f i
.
ofFn f = #[f 0, f 1, ... , f(n - 1)]
Equations
- Array.ofFn f = Array.ofFn.go f 0 (Array.mkEmpty n)
Instances For
Auxiliary for ofFn
. ofFn.go f i acc = acc ++ #[f i, ..., f(n - 1)]
Equations
- Array.ofFn.go f i acc = if h : i < n then Array.ofFn.go f (i + 1) (Array.push acc (f { val := i, isLt := h })) else acc
Instances For
The array #[0, 1, ..., n - 1]
.
Equations
- Array.range n = Nat.fold (flip Array.push) n #[]
Instances For
Turns #[#[a₁, a₂, ⋯], #[b₁, b₂, ⋯], ⋯]
into #[a₁, a₂, ⋯, b₁, b₂, ⋯]
Equations
- Array.flatten arr = Array.foldl (fun (acc a : Array α) => Array.append acc a) #[] arr 0