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).
Parameters
| f | the function to lift |
Example
The function itself. (arr (fn [x] (+ x 1))) ; => identity for functions
defn
>>>
(>>> [f g])
compose two function arrows sequentially.
Parameters
| f | first arrow (a -> b) | |
| g | second arrow (b -> c) |
Example
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.
Parameters
| f | function to apply |
Example
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.
Parameters
| f | function to apply |
Example
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.
Parameters
| ^arr | the arrow type constructor | |
| a | the type parameter |
Example
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.
Parameters
| ^arr | the arrow type constructor | |
| f | first arrow (a -> b) | |
| g | second arrow (b -> c) |
Example
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.
Parameters
| f | function a -> b | |
| g | function c -> d |
Example
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.
Parameters
| f | function a -> b | |
| g | function a -> c |
Example
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.