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 [x :int])

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)

return the none Option[A] (NULL).

0 (NULL) representing the absent option.

(none)  ; => none

Since: Phase TC1

defn

some?

(some? [o :int])

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 [o :int dflt :int])

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

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 [o :int f])

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)

Since: Phase TC1

defn

option-eq?

(option-eq? [o1 :int o2 :int cmp-fn])

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.