No matching definitions.

tur/saffron/prelude

stdlib/saffron/prelude.tur
defn

vec-map-loop__

(vec-map-loop__ [v :(Vec any) f :(fn [any] any) out :(Vec any) i :int n :int] :int)

the Saffron dialect's prelude.

Since: saffron-lang-plan S6

defn

vec-map

(vec-map [v :(Vec any) f :(fn [any] any)] :(Vec any))

apply f to each element of a vector, into a fresh vector.

v(Vec any), e.g. a `[...]` literal
fa one-argument function over `any`

A fresh (Vec any) of the same length. The caller owns it.

(vec-map [1 2 3] (fn [x] (* x 2)))   ; => 2 4 6

Since: saffron-lang-plan S6

defn

vec-filter-loop__

(vec-filter-loop__ [v :(Vec any) pred :(fn [any] any) out :(Vec any) i :int n :int] :int)

internal: the recursive half of vec-filter.

defn

vec-filter

(vec-filter [v :(Vec any) pred :(fn [any] any)] :(Vec any))

keep the elements of a vector for which pred is truthy.

v(Vec any)
preda one-argument predicate over `any`. D4 truthiness applies, so
only nil and `false` drop an element -- an empty string and a zero
are both kept.

A fresh (Vec any) holding the kept elements, in order. The caller owns it.

(vec-filter [1 2 3 4] (fn [x] (> x 2)))   ; => 3 4

Since: saffron-lang-plan S6

defn

vec-fold-loop__

(vec-fold-loop__ [v :(Vec any) f :(fn [any any] any) acc :any i :int n :int] :any)

internal: the recursive half of vec-fold.

defn

vec-fold

(vec-fold [v :(Vec any) init :any f :(fn [any any] any)] :any)

left-fold a vector with an accumulator.

v(Vec any)
initthe starting accumulator
f(fn [acc x] acc')

The final accumulator.

(vec-fold [1 2 3] 0 (fn [a x] (+ a x)))   ; => 6

Since: saffron-lang-plan S6