# Quark.SKI(Quark v2.3.2) View Source

The classic SKI system of combinators. `s` and `k` alone can be used to express any algorithm, though generally not efficiently.

# Link to this section Summary

## Functions

The identity combinator. Also aliased as `id`.

The constant ("Konstant") combinator. Returns the first argument unchanged, and discards the second argument.

The "substitution" combinator. Applies the last argument to the first two, and then the first two to each other.

Opposite of `first` (the `k` combinator).

View Source

View Source

# i()

View Source

The identity combinator. Also aliased as `id`.

``````iex> i(1)
1

iex> i("identity combinator")
"identity combinator"

iex> [1,2,3] |> id
[1,2,3]``````

# i(x)

View Source

## Specs

`i(any()) :: any()`

View Source

# k()

View Source

The constant ("Konstant") combinator. Returns the first argument unchanged, and discards the second argument.

Can be used to repeatedly apply the same value in functions such as folds.

Aliased as `first` and `constant`.

## Examples

``````iex> k(1, 2)
1

"happy"

iex> Enum.reduce([1,2,3], [42], &k/2)
3

iex> Enum.reduce([1,2,3], [42], &constant/2)
3

iex> first(1,2)
1``````

View Source

# k(x, y)

View Source

## Specs

`k(any(), any()) :: any()`

# s()

View Source

The "substitution" combinator. Applies the last argument to the first two, and then the first two to each other.

## Examples

``````iex> add = &(&1 + &2)
...> double = &(&1 * 2)
24``````

View Source

View Source

# s(x, y, z)

View Source

## Specs

`s((... -> any()), (... -> any()), any()) :: any()`

# second()

View Source

Opposite of `first` (the `k` combinator).

While not strictly part of SKI, it's a common enough case.

Returns the second of two arguments. Can be used to repeatedly apply the same value in functions such as folds.

## Examples

``````iex> second(43, 42)
42

iex> Enum.reduce([1,2,3], [], &second/2)
[]``````
`second(any(), any()) :: any()`