No matching definitions.

tur/option

stdlib/option.tur
defdata

Option

(defdata Option :copy [A] (None) (Some A))

typed Option[A]: parameterized optional value.

First-class parameterized optional value, as a REAL SUM (SR2b of docs/archive/sum-representation-plan.md): (None) or (Some A). Runtime layout is the tagged monomorph -- { int tag; union { None; Some } } -- 16 bytes, with no dead arm to zero-fill. A concrete monomorph flows BY VALUE with no per-ctor allocation (SR2a, default since 2026-08-27); an erased generic base still rides the int64 carrier, a heap pointer to the same layout, and (none) IS the null pointer there (SR3 slice A). Tag values follow declaration order: None = 0, Some = 1. The inline-C helpers in the codegen preamble (tur_box_some / tur_is_some / tur_opt_value / tur_some_ptr / tur_none) build and read this exact layout; keep them in lockstep with this declaration.

Option -- parameterized optional value containing either some A or none.

Since: Phase TC1

defn

some

(some [A])

wrap a value of type A in a some Option[A].

xthe value to wrap (type A)

An Option[A] carrying the Some variant.

(some 42)  ; => some(42)

Since: Phase TC1

defn

none

(none [A] :(Option A))

return the none Option[A].

The None variant. (SR3 slice A: on the carrier path None IS the null carrier -- construction allocates nothing, and every reader treats 0 as none. A tagged None box remains valid on the read side.)

(none)  ; => none

Since: Phase TC1

defn

some?

(some? [A])

check whether an Option[A] contains a value.

oOption[A]

true if o is some, false if o is none.

(some? (some 1))  ; => true
(some? (none))    ; => false

Since: Phase TC1

defn

none?

(none? [A])

check whether an Option[A] is empty.

The complement of some?. It existed in the compiler's pure-builtin list (src/compiler/emit_fns.c) with no implementation behind it, which made it worse than simply absent: the compiled path rejected it as an unknown function, while the interpreter treated the name as known and answered false for EVERY argument, with no warning -- so (none? (none)) was false at the REPL. See docs/archive/quickstart-tutorial-fictional-option-api.md.

oOption[A]

true if o is none, false if o is some.

(none? (none))    ; => true
(none? (some 1))  ; => false

Since: 2026-08-20

defn

unwrap

(unwrap [A])

extract the value from a typed Option[A].

oOption[A]

The contained value of type A; the zero value of A when o is none (preserving the pre-sum behaviour, where none's dead value slot held (default-of A)).

(unwrap (some 7))  ; => 7

Since: Phase TC1

defn

unwrap-or

(unwrap-or [A])

extract the value or return a default.

oOption[A]
dfltvalue to return if o is none (type A)

The contained value, or default if none.

(unwrap-or (none) 99)   ; => 99
(unwrap-or (some 7) 99) ; => 7

Since: Phase TC1

defn

unwrap-or-carrier

(unwrap-or-carrier [o :int dflt :int])

carrier-ABI shim for the Track A cascade: extract the value from the int64 carrier Option, or return dflt. Temporary surface for producers that still return the carrier Option (e.g. zipper / kleisli); retired once those producers move to by-value (Option A). See docs/archive/history/unwrap-or-byvalue-cascade.md.

defn

option-free

(option-free [o :int])

free a heap-allocated Option[A].

oOption[A] to free (may be none / 0)
(option-free my-opt)

Since: Phase TC1

defn

option-map

(option-map [A B])

apply a function to the contained value if some.

oOption[A]
ffunction A -> B

Option[B] with f applied if some, or none.

(option-map (some 3) (fn [x] (* x 2)))  ; => some(6)

Note:

Mapping over a *literal* `(none)` with an *unannotated* lambda leaves the
element type under-determined (`(none)` carries no element type) and fails
to compile -- annotate the lambda or map over a typed Option value. See
docs/archive/history/option-map-literal-none-unannotated-fn-no-A-inference.md.

Since: Phase TC1

defn

option-eq?

(option-eq? [A])

compare two Option[A] values using a comparator.

o1first Option[A]
o2second Option[A]
cmp-fncomparator fn [a :int b :int] :bool

true if both none, or both some with equal values.

(option-eq? (some 1) (some 1) (fn [a b] (= a b)))  ; => true

Since: Phase TC1

definstance

Eq[Option]

(definstance Eq [Option])

equality using the inner type's Eq instance.

definstance

Functor[Option]

(definstance Functor [Option])

map a function over the some payload; none unchanged.

(fmap (some 21) (fn [x] (* x 2)))  ; => some(42)

Since: stdlib-hkt-consolidation T1

definstance

Applicative[Option]

(definstance Applicative [Option])

pure wraps in some; ap applies a some function to a some argument (none when either side is none).

(ap (some f) (some 3))  ; => some(f 3)

Since: stdlib-hkt-consolidation T1

definstance

Monad[Option]

(definstance Monad [Option])

bind sequences through some; short-circuits on none.

(bind (some 20) (fn [x] (some (+ x 1))))  ; => some(21)

Since: stdlib-hkt-consolidation T1

definstance

Alternative[Option]

(definstance Alternative [Option])

empty is none; alt-or picks the first some.

(alt-or (none) (some 7))  ; => some(7)

Since: stdlib-hkt-consolidation T1