std.function

compose : forall a b c. (b -> c) -> (a -> b) -> a -> c

Function composition, from right to left. That is, compose f g x is f (g x).

Examples

let f = std.function.compose (fun x => x + 1) (fun x => x / 2)
in
f 10
# => (10 / 2) + 1
# => 6

const : forall a b. a -> b -> a

Takes a value and returns the constant function which always returns this value. Same as std.function.first.

Examples

let f = std.function.const 5 in
f 7
# => 5

first : forall a b. a -> b -> a

Always returns the first argument, ignoring the second. Same as std.function.const.

Examples

std.function.first 5 7
# => 5

flip : forall a b c. (a -> b -> c) -> b -> a -> c

Flips the argument order for a two-argument function.

Examples

std.function.flip (fun x y => "%{x} %{y}") "world!" "Hello,"
# => "Hello, world!"

id : forall a. a -> a

The identity function, that is, id x is x for any value x.

Examples

std.function.id null
# => null

(std.function.id (fun x => x + 1)) 0
# => 1

pipe : forall a. a -> Array (a -> a) -> a

Applies an array of functions to a value, in order.

Examples

std.function.pipe 2 [ (+) 2, (+) 3 ]
# => 7

std.function.pipe 'World [ std.string.from, fun s => "Hello, %{s}!" ]
# => "Hello, World!"

second : forall a b. a -> b -> b

Always returns the second argument, ignoring the first.

Examples

std.function.second 5 7
# => 7