General combinators
These are general functions, which do not pertain to any domain in particular. They are typically used in combination with other functions.
id : a -> a
The identity function, which simply returns whatever input it is given.
val a = id 14
// = 14
val b = id "some text"
// = "some text"
const : a -> b -> a
const x
is a function which returns x
no matter what input it is given, i.e., the constant x
function.
val x = const 30 100
// = 30
val f = const 0
// = \_ -> 0
flip : (a -> b -> c) -> b -> a -> c
Flips the order of the first two arguments of a function.
Examples
val a = flip (\x -> \y -> x) 10 20
// = 20
comp: (a -> b) -> (c -> a) -> c -> b
Composes two unary functions.
Examples
val a = comp (\x -> x + 5) (\y -> y * 12) 5
// = (\x -> x + 5) 60 = 65
via: (a -> b) -> (b -> b -> c) -> (a -> a -> c)
via f g x y
transforms x
and y
using unary function f
and applies the results to binary function g
.
Examples
val a = via fst compareInt (1, 3.15) (2, 0.75)
// = Less
val b = via snd compareFloat (1, 3.15) (2, 0.75)
// = Greater
min : (a -> a -> Ordering) -> a -> a -> a
Returns the smaller of the two last arguments, using the comparison function provided as the first argument. Examples ^^^^^^^^
val a = min compareInt 8 9
// = 8
val b = min compareFloat 4.233 3.11
// = 3.11
max : (a -> a -> Ordering) -> a -> a -> a
Returns the larger of the two last arguments, using the comparison function provided as the first argument. Examples ^^^^^^^^
val a = max compareInt 8 9
// = 9
val b = max compareFloat 4.233 3.11
// = 4.233