Abstract

Simple functional combinators.

Synopsis

val |> '^a '^b : (x: a) -> (f: a -> b) -> b
val <| '^a '^b : (f: a -> b) -> (x: a) -> b
val >-> '^a '^b '^c : (f: a -> b) -> (g: b -> c) -> (x: a) -> c
val <-< '^a '^b '^c : (g: b -> c) -> (f: a -> b) -> (x: a) -> c
val flip '^a '^b '^c : (f: a -> b -> c) -> (b: b) -> (a: a) -> c
val curry '^a '^b '^c : (f: (a, b) -> c) -> (a: a) -> (b: b) -> c
val uncurry '^a '^b '^c : (f: a -> b -> c) -> (a, b) -> c
val const '^a '^b : (x: a) -> b -> a
val id '^a : (x: a) -> a
val iterate 'a : (n: i32) -> (f: a -> a) -> (x: a) -> a
val iterate_until 'a : (p: a -> bool) -> (f: a -> a) -> (x: a) -> a
val iterate_while 'a : (p: a -> bool) -> (f: a -> a) -> (x: a) -> a

Description

val |> '^a '^b: (x: a) -> (f: a -> b) -> b

Left-to-right application. Particularly useful for describing computation pipelines:

x |> f |> g |> h
val <| '^a '^b: (f: a -> b) -> (x: a) -> b

Right to left application.

Due to the causality restriction (see the language reference) this is less useful than |>. For example, the following is a type error:

length <| filter (>0) [-1,0,1]

But this works:

filter (>0) [-1,0,1] |> length
val >-> '^a '^b '^c: (f: a -> b) -> (g: b -> c) -> (x: a) -> c

Function composition, with values flowing from left to right.

Note that functions with anonymous return sizes cannot be composed. For example, the following is a type error:

filter (>0) >-> length

In such cases you can use the pipe operator |> instead.

val <-< '^a '^b '^c: (g: b -> c) -> (f: a -> b) -> (x: a) -> c

Function composition, with values flowing from right to left. This is the same as the operator known from mathematics.

Has the same restrictions with respect to anonymous sizes as >->.

val flip '^a '^b '^c: (f: a -> b -> c) -> (b: b) -> (a: a) -> c

Flip the arguments passed to a function.

f x y == flip f y x
val curry '^a '^b '^c: (f: (a, b) -> c) -> (a: a) -> (b: b) -> c

Transform a function taking a pair into a function taking two arguments.

val uncurry '^a '^b '^c: (f: a -> b -> c) -> (a, b) -> c

Transform a function taking two arguments in a function taking a pair.

val const '^a '^b: (x: a) -> b -> a

The constant function.

val id '^a: (x: a) -> a

The identity function.

val iterate 'a: (n: i32) -> (f: a -> a) -> (x: a) -> a

Apply a function some number of times.

val iterate_until 'a: (p: a -> bool) -> (f: a -> a) -> (x: a) -> a

Keep applying f until p returns true for the input value. May apply zero times. Note: may not terminate.

val iterate_while 'a: (p: a -> bool) -> (f: a -> a) -> (x: a) -> a

Keep applying f while p returns true for the input value. May apply zero times. Note: may not terminate.