No matching definitions.

tur/result

stdlib/result.tur

typed Result[A B]: ok value A or err value B.

Since: Phase TC1-E

defstruct

Result

(defstruct Result [A B])

parameterized result type with ok type A and err type B.

Since: Phase TC1

defn

ok

(ok [A B])

wrap a success value of type A in a Result[A B].

xthe ok value (type A)

A Result[A B] with is-ok=true. B is a phantom tyvar inferred from the call site (or pinned with an ascription such as `(:: (ok x) (Result A B))`).

(ok 42)                        ; => Result int B  (B inferred)
  (:: (ok "hi") (Result cstr cstr))

Since: Phase TC1 (made polymorphic over A/B as Prereq 3, 2026-06-12;

defn

err

(err [A B])

wrap an error value of type B in a Result[A B].

ethe error value (type B)

A Result[A B] with is-ok=false. A is a phantom tyvar inferred from the call site (or pinned with an ascription such as `(:: (err msg) (Result A B))`).

(err 404)                       ; => Result A int   (A inferred)
  (:: (err "missing") (Result int cstr))

Since: Phase TC1 (made polymorphic as Prereq 3, 2026-06-12; same

defn

ok?

(ok? [r : int])

check whether a Result[A B] is ok.

rResult[A B]

true if r is ok, false if r is err.

(ok? (ok 1))   ; => true
  (ok? (err 0))  ; => false

Since: Phase TC1

defn

err?

(err? [r : int])

check whether a Result[A B] is err.

rResult[A B]

true if r is err, false if r is ok.

(err? (err 1))  ; => true

Since: Phase TC1

defn

ok-val

(ok-val [A B])

extract the ok value from a typed Result[A B].

rResult[A B]

The ok value of type A.

(let [r (:: (make-struct Result true 7 "err") (Result int cstr))]
    (ok-val r))  ; => 7

Since: Phase TC1

defn

err-val

(err-val [A B])

extract the error value from a typed Result[A B].

rResult[A B]

The error value of type B.

(let [r (:: (make-struct Result false 0 "boom") (Result int cstr))]
    (err-val r))  ; => "boom"

Since: Phase TC1

defn

result-free

(result-free [r : int])

free a heap-allocated Result[A B].

rResult[A B] to free
(result-free my-result)

Since: Phase TC1

defn

result-map

(result-map [A B E])

apply a function to the ok value if ok.

rResult[A B]
ffunction A -> C

Result[C B] with f applied to the ok value if ok, or the unchanged err otherwise. The returned value is a freshly allocated Result; the input r is not modified.

(result-map (ok 3) (fn [x] (* x 2)))  ; => ok(6)
  (result-map (err 5) (fn [x] (* x 2))) ; => err(5)

Since: Phase TC1

defn

result-eq?

(result-eq? [r1 : int r2 : int ^fat ok-cmp ^fat err-cmp])

compare two Result[A B] values.

r1first Result[A B]
r2second Result[A B]
ok-cmpcomparator for ok values fn [a :int b :int] :bool
err-cmpcomparator for err values fn [a :int b :int] :bool

true if both ok with equal ok values, or both err with equal err values.

(result-eq? (ok 1) (ok 1) (fn [a b] (= a b)) (fn [a b] (= a b)))  ; => true

Since: Phase TC1

definstance

Eq[Result]

(definstance Eq [Result])

equality using the ok and err types' Eq instances.

defn

result-bimap

(result-bimap [container : int fn-left fn-right])

map fn-left over the err arm and fn-right over the ok arm.

containerResult[A B]
fn-leftfunction applied to the err value (B -> D)
fn-rightfunction applied to the ok value (A -> C)

A freshly allocated Result[C D]; the input is not modified.

(result-bimap (ok 5) neg inc)   ; => ok(6)
  (result-bimap (err 5) neg inc)  ; => err(-5)

Since: stdlib-hkt-consolidation T1

definstance

Bifunctor[Result]

(definstance Bifunctor [Result])

map fn-left over err, fn-right over ok.

(bimap (ok 5) neg inc)   ; => ok(6)
  (bimap (err 5) neg inc)  ; => err(-5)

Since: stdlib-hkt-consolidation T1

definstance

Functor[]

(definstance Functor [])

map a function over the ok payload; err unchanged.

(fmap (:: (ok 21) (Result int int)) (fn [x] (* x 2)))  ; => ok(42)
  (fmap (:: (err 5) (Result int int)) (fn [x] (* x 2)))  ; => err(5)

Since: stdlib-hkt-consolidation T4

definstance

Monad[]

(definstance Monad [])

bind sequences through ok; short-circuits on err.

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

Since: stdlib-hkt-consolidation T4

definstance

MonadError[]

(definstance MonadError [])

throw-error builds an err; catch-error runs a

(throw-error 404)                              ; => err(404)
  (catch-error (err 5) (fn [e] (ok (* e -1))))   ; => ok(-5)
  (catch-error (ok 7) (fn [e] (ok 0)))           ; => ok(7)

Since: stdlib-hkt-consolidation T4

Internal definitions
__tur-q-is-err?-- ? operator helper; checks if a Result value is an error.
__tur-q-ok-val-- ? operator helper; extracts the ok payload from a Result value.