No matching definitions.

tur/either

stdlib/either.tur

binary sum type Either[L R]: Left l or Right r.

Since: Phase sum-types-either

defdata

Either

(defdata Either :copy [L R] (Left) (Right))
defn

left?

(left? [e : int] :)

is this Either a Left?

ean Either[L R] handle

true when e is (Left _), false when (Right _).

(left? (Left 3))   ; => true
  (left? (Right 3))  ; => false

Since: Phase sum-types-either

defn

right?

(right? [e : int] :)

is this Either a Right?

ean Either[L R] handle

true when e is (Right _), false when (Left _).

(right? (Right 3))  ; => true
  (right? (Left 3))   ; => false

Since: Phase sum-types-either

defn

from-left

(from-left [dflt : int e : int] :)

extract the Left payload, or a default when e is a Right.

dfltvalue returned when e is a Right
ean Either[L R] handle

The L payload when e is (Left l), else dflt.

(from-left 0 (Left 7))   ; => 7
  (from-left 0 (Right 7))  ; => 0

Since: Phase sum-types-either

defn

from-right

(from-right [dflt : int e : int] :)

extract the Right payload, or a default when e is a Left.

dfltvalue returned when e is a Left
ean Either[L R] handle

The R payload when e is (Right r), else dflt.

(from-right 0 (Right 7))  ; => 7
  (from-right 0 (Left 7))   ; => 0

Since: Phase sum-types-either

defn

either

(either [^fat on-left : (fn [int])

eliminate an Either by applying one of two functions.

on-leftfunction applied to the Left payload (carried as a fat closure)
on-rightfunction applied to the Right payload (carried as a fat closure)
ean Either[L R] handle

(on-left l) when e is (Left l), else (on-right r).

(either negate id (Left 5))   ; => -5
  (either negate id (Right 5))  ; => 5

Since: Phase sum-types-either

defn

either-map

(either-map [^fat f : (fn [int])

map a function over the Right arm (right-biased).

ffunction applied to the Right payload (carried as a fat closure)
ean Either[L R] handle

(Right (f r)) when e is (Right r), else e unchanged.

(either-map inc (Right 4))  ; => (Right 5)
  (either-map inc (Left 4))   ; => (Left 4)

Since: Phase sum-types-either

defn

either-map-left

(either-map-left [^fat f : (fn [int])

map a function over the Left arm.

ffunction applied to the Left payload (carried as a fat closure)
ean Either[L R] handle

(Left (f l)) when e is (Left l), else e unchanged.

(either-map-left inc (Left 4))   ; => (Left 5)
  (either-map-left inc (Right 4))  ; => (Right 4)

Since: Phase sum-types-either

definstance

Functor[]

(definstance Functor [])

right-biased Functor for Either: map over Right.

Since: Phase sum-types-either