# Function Reference

## General Functions

### id

``````id : forall a. a -> a
``````

The identity function does nothing and just returns its value.

### const

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

The function `const a` always returns `a`.

### flip

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

### apply

``````apply : forall a b. (a -> b) -> a -> b
``````

### (<|)

Infix operator alias for apply. right-associative, precedence: 0

Apply the function on the left-hand side to the argument on the right-hand side.

### applyFlipped

``````applyFlipped : forall a b. a -> (a -> b) -> b
``````

### (|>)

Infix operator alias for applyFlipped. left-associative, precedence: 1

Apply the function on the right-hand side to the argument on the left-hand side.

### compose

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

### (<<<)

Infix operator alias for compose. right-associative, precedence: 9

### composeFlipped

``````composeFlipped : forall a b c. (a -> b) -> (b -> c) -> a -> c
``````

### (>>>)

Infix operator alias for composeFlipped. right-associative, precedence: 9

## Boolean Values

### Boolean

``````type Boolean
``````

#### Constructors

• `True`

• `False`

### conj

``````conj : Boolean -> Boolean -> Boolean
``````

Conjunction of two booleans. The result is true if both arguments are true.

### (&&)

Infix operator alias for conj. right-associative, precedence: 3

### disj

``````disj : Boolean -> Boolean -> Boolean
``````

Disjunction of two booleans. The result is true if the first, the second, or both arguments are true.

### (||)

Infix operator alias for disj. right-associative, precedence: 2

### not

``````not : Boolean -> Boolean
``````

Negate a boolean value.

## Numeric Values

### Num

``````interface Num x where
``````

#### Methods

• `add : x -> x -> x`

• `sub : x -> x -> x`

• `mul : x -> x -> x`

• `div : x -> x -> x`

• `one : x`

• `zero : x`

#### Implementations

• `Num Integer`
• `Num Number`

### (+)

Infix operator alias for add. left-associative, precedence: 6

### (-)

Infix operator alias for sub. left-associative, precedence: 6

### (*)

Infix operator alias for mul. left-associative, precedence: 7

### (/)

Infix operator alias for div. left-associative, precedence: 7

### roundTo

``````roundTo : Integer -> Number -> Number
``````

For example, the expression `roundTo 2 n` rounds the number `n` to a

### toNumber

``````toNumber : Integer -> Number
``````

## Equality

### Eq

``````interface Eq a where
``````

Interface of types where elements can be compared to each other.

#### Methods

• `eq : a -> a -> Boolean`

Returns true if both arguments are equal.

#### Implementations

• `Eq Integer`
• `Eq Number`
• `Eq String`
• `Eq DateTime`
• `Eq (Row t)`
• `Eq Boolean`
• `Eq a => Eq b => Eq (Pair a b)`
• `Eq a => Eq (List a)`
• `Eq a => Eq (Maybe a)`
• `Eq a => Eq b => Eq (Either a b)`

### (==)

Infix operator alias for eq. non-associative, precedence: 4

### notEq

``````notEq : forall a. Eq a => a -> a -> Boolean
``````

Returns true if both arguments are not equal.

### (/=)

Infix operator alias for notEq. non-associative, precedence: 4

## Ordering

### Ordering

``````type Ordering
``````

The type returned by `compare`.

#### Constructors

• `EQ`

Both elements are equal.

• `LT`

The first element is less than the second one.

• `GT`

The first element is greater than the second one.

### Ord

``````interface Eq a => Ord a where
``````

Interface of types that can be ordered.

#### Methods

• `compare : a -> a -> Ordering`

Compares two elements.

#### Implementations

• `Ord Number`
• `Ord Integer`
• `Ord DateTime`

### lessThan

``````lessThan : forall a. Ord a => a -> a -> Boolean
``````

Returns true if the first argument is less than the second.

### (<)

Infix operator alias for lessThan. left-associative, precedence: 4

### greaterThan

``````greaterThan : forall a. Ord a => a -> a -> Boolean
``````

Returns true if the first argument is more than the second.

### (>)

Infix operator alias for greaterThan. left-associative, precedence: 4

### lessThanOrEq

``````lessThanOrEq : forall a. Ord a => a -> a -> Boolean
``````

Returns true if the first argument is less than or equal to the second.

### (<=)

Infix operator alias for lessThanOrEq. left-associative, precedence: 4

### greaterThanOrEq

``````greaterThanOrEq : forall a. Ord a => a -> a -> Boolean
``````

Returns true if the first argument is more than or equal to the second.

### (>=)

Infix operator alias for greaterThanOrEq. left-associative, precedence: 4

### min

``````min : forall a. Ord a => a -> a -> a
``````

### max

``````max : forall a. Ord a => a -> a -> a
``````

## Pairs

### Pair

``````type Pair a b
``````

#### Constructors

• `Pair a b`

## Lists

### List

``````type List a
``````

#### Constructors

• `Nil`

• `Cons a (List a)`

### member

``````member : forall a. Eq a => a -> List a -> Boolean
``````

### sum

``````sum : forall a. Num a => List a -> a
``````

Calculates the sum over a list of numbers.

### length

``````length : forall a. List a -> Integer
``````

Get the length of a list.

### filter

``````filter : forall a. (a -> Boolean) -> List a -> List a
``````

Filter a list according to the given predicate. For example,

``````predicate x = x.Temperature >= 0 && x.Temperature <= 10
filter predicate #Cities
``````

would filter the rows of the "Cities" table to include only those where the temperature is between `0` and `10` degrees.

### find

``````find : forall a. (a -> Boolean) -> List a -> Maybe a
``````

Find the first element in a list that matches the given predicate, or return `Nothing`.

### concat

``````concat : forall a. List (List a) -> List a
``````

Flatten a list of lists.

### any

``````any : forall a. (a -> Boolean) -> List a -> Boolean
``````

### all

``````all : forall a. (a -> Boolean) -> List a -> Boolean
``````

## Maybe Values

### Maybe

``````type Maybe a
``````

#### Constructors

• `Nothing`

• `Just a`

### maybe

``````maybe : forall a b. b -> (a -> b) -> Maybe a -> b
``````

The expression `maybe b f x` applies the function `f` to the content of x, or just returns `b`, if x is `Nothing`.

### fromMaybe

``````fromMaybe : forall a. a -> Maybe a -> a
``````

The expression `fromMaybe 0 x` returns the content of x if there is one, or `0` in case of `Nothing`.

### mapMaybe

``````mapMaybe : forall a b. (a -> Maybe b) -> List a -> List b
``````

## Either Values

### Either

``````type Either a b
``````

#### Constructors

• `Left a`

• `Right b`

### either

``````either : forall a b c. (a -> c) -> (b -> c) -> Either a b -> c
``````

## Containers

### Functor

``````interface Functor f where
``````

Interface of types that represent "containers" which can be mapped over.

#### Methods

• `map : forall a b. (a -> b) -> f a -> f b`

Apply a function to every element in the container `f` (e.g., a list), and return the result.

#### Implementations

• `Functor List`
• `Functor Maybe`
• `Functor (Either a)`

## Appendable Values

### Semigroup

``````interface Semigroup a where
``````

Interface of types where elements can be "appended" to one another.

#### Methods

• `append : a -> a -> a`

Appends two values of `a` to get a new value of `a`. Example: ```"Hello " <> name```

#### Implementations

• `Semigroup (List a)`
• `Semigroup String`

### (<>)

Infix operator alias for append. right-associative, precedence: 5

## Foldable Values

### Foldable

``````interface Foldable f where
``````

#### Methods

• `foldl : forall a b. (b -> a -> b) -> b -> f a -> b`

• `foldr : forall a b. (a -> b -> b) -> b -> f a -> b`

#### Implementations

• `Foldable List`
• `Foldable Maybe`

## Printable Values

### Print

``````interface Print a where
``````

Interface of types that can be converted into a `String`.

#### Methods

• `print : a -> String`

Convert the argument into a string.

#### Implementations

• `Print Boolean`
• `Print Integer`
• `Print Number`
• `Print String`

## Formatting

### formatNumber

``````formatNumber : String -> Number -> String
``````

A call like `formatNumber s x` formats the number `x` according to the format string `s`. For a list of formatting characters, see here.

### formatDateTime

``````formatDateTime : String -> DateTime -> String
``````

`formatDateTime s t` formats time `t` according to the format string `s`. For a list of formatting characters see here.

## Date and Time

### year

``````year : DateTime -> Integer
``````

Returns the year of a given time.

### month

``````month : DateTime -> Integer
``````

Returns the month of the year (1-12) of a given time.

### day

``````day : DateTime -> Integer
``````

Returns the day of the month (1-31) of a given time.