tur/arrow

stdlib/arrow.tur
definstance

Arrow[->]

(definstance Arrow [->])

Arrow instance for plain functions (->).

definstance

ArrowChoice[->]

(definstance ArrowChoice [->])

ArrowChoice instance for plain functions (->).

definstance

ArrowZero[->]

(definstance ArrowZero [->])

ArrowZero instance for plain functions (->).

definstance

ArrowPlus[->]

(definstance ArrowPlus [->])

ArrowPlus instance for plain functions (->).

definstance

ArrowLoop[->]

(definstance ArrowLoop [->])

ArrowLoop instance for plain functions (->).

definstance

ArrowApply[->]

(definstance ArrowApply [->])

ArrowApply instance for plain functions (->).

defn

arr

(arr [f])

lift a function to an arrow (identity for function arrows).

fthe function to lift
The function itself.

  (arr (fn [x] (+ x 1)))  ; => identity for functions
defn

>>>

(>>> [f g])

compose two function arrows sequentially.

ffirst arrow (a -> b)
gsecond arrow (b -> c)
A function (a -> c) that applies f then g.

  ((>>> (fn [x] (+ x 1)) (fn [x] (* x 2))) 3)  ; => 8
defn

arrow-first

(arrow-first [f])

apply a function to the first component of a Pair.

ffunction to apply
A function on Pair that applies f to the first field.

  ((arrow-first (fn [x] (+ x 1))) (Pair 5 10))  ; => Pair(6, 10)
defn

arrow-second

(arrow-second [f])

apply a function to the second component of a Pair.

ffunction to apply
A function on Pair that applies f to the second field.

  ((arrow-second (fn [x] (+ x 1))) (Pair 5 10))  ; => Pair(5, 11)
defn

arrow-id

(arrow-id [a])

identity arrow for any Arrow instance.

^arrthe arrow type constructor
athe type parameter
An arrow that passes its input unchanged.

  (arrow-id)  ; => arr (fn [x] x)
defn

arrow-comp

(arrow-comp [a b c f g])

compose two arrows sequentially.

^arrthe arrow type constructor
ffirst arrow (a -> b)
gsecond arrow (b -> c)
An arrow (a -> c) that applies f then g.

  (arrow-comp f g)  ; => f >>> g
defn

par-comp

(par-comp [a b c d f g])

parallel composition of two functions on Pair types.

ffunction a -> b
gfunction c -> d
A function on Pair a c -> Pair b d: (par-comp f g)(Pair x y) = Pair(f x, g y).

  ((par-comp inc double) (Pair 1 2))  ; => Pair(2, 4)
defn

arrow-split

(arrow-split [a b c f g])

duplicate input and apply two functions, returning a Pair.

ffunction a -> b
gfunction a -> c
A function a -> Pair b c: (arrow-split f g)(x) = Pair(f x, g x).

  ((arrow-split inc double) 3)  ; => Pair(4, 6)
Internal definitions
__arrow_call1-- call a function stored as int64 with one argument.
__arrow_call2-- call a function stored as int64 with two arguments.