No matching definitions.

tur/option

stdlib/option.tur

typed Option[A]: parameterized optional value.

Since: Phase TC1-D

defstruct

Option

(defstruct Option [A])

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, stored as int64_t)

A heap-allocated Option[A] with is-some=true.

(some 42)  ; => some(42)

Since: Phase TC1

defn

none

(none [A])

return the none Option[A] (NULL).

0 (NULL) representing the absent option.

(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

unwrap

(unwrap [A])

extract the value from a typed Option[A].

oOption[A]

The contained value of type A.

(let [o (:: (make-struct Option true 7) (Option int))]
    (unwrap o))  ; => 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

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/reported/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

(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