Copyright | (c) Justus Adam, 2015 |
---|---|

License | BDS3 |

Maintainer | dev@justus.science |

Stability | experimental |

Portability | POSIX, Windows |

Safe Haskell | Safe |

Language | Haskell2010 |

- get :: Int -> [α] -> Maybe α
- slice :: Int -> Int -> [α] -> [α]
- to1Value :: [α] -> Maybe α
- to2Tuple :: [α] -> Maybe (α, α)
- to3Tuple :: [α] -> Maybe (α, α, α)
- to4Tuple :: [α] -> Maybe (α, α, α, α)
- to5Tuple :: [α] -> Maybe (α, α, α, α, α)
- to6Tuple :: [α] -> Maybe (α, α, α, α, α, α)
- to7Tuple :: [α] -> Maybe (α, α, α, α, α, α, α)
- to8Tuple :: [α] -> Maybe (α, α, α, α, α, α, α, α)
- to9Tuple :: [α] -> Maybe (α, α, α, α, α, α, α, α, α)
- to10Tuple :: [α] -> Maybe (α, α, α, α, α, α, α, α, α, α)
- fillZip :: [α] -> [β] -> [(Maybe α, Maybe β)]
- fillZip2 :: [α] -> [β] -> [(Maybe α, Maybe β)]
- fillZip3 :: [α] -> [β] -> [γ] -> [(Maybe α, Maybe β, Maybe γ)]
- fillZip4 :: [α] -> [β] -> [γ] -> [δ] -> [(Maybe α, Maybe β, Maybe γ, Maybe δ)]
- fillZip5 :: [α] -> [β] -> [γ] -> [δ] -> [ζ] -> [(Maybe α, Maybe β, Maybe γ, Maybe δ, Maybe ζ)]
- monoidFillZip :: (Monoid α, Monoid β) => [α] -> [β] -> [(α, β)]
- monoidFillZip2 :: (Monoid α, Monoid β) => [α] -> [β] -> [(α, β)]
- monoidFillZip3 :: (Monoid α, Monoid β, Monoid γ) => [α] -> [β] -> [γ] -> [(α, β, γ)]
- monoidFillZip4 :: (Monoid α, Monoid β, Monoid γ, Monoid δ) => [α] -> [β] -> [γ] -> [δ] -> [(α, β, γ, δ)]
- monoidFillZip5 :: (Monoid α, Monoid β, Monoid γ, Monoid δ, Monoid ζ) => [α] -> [β] -> [γ] -> [δ] -> [ζ] -> [(α, β, γ, δ, ζ)]

# Reading values

get :: Int -> [α] -> Maybe α Source

The function that `!!`

should be.

The `get`

function attempts to extract the element at the specified index from
the list, but instead of failing with an error returns a `Maybe`

value.

`>>>`

Just 1`get 0 [1, 2, 3]`

`>>>`

Just 3`get 2 [1, 2, 3]`

`>>>`

Nothing`get 3 [1, 2, 3]`

This function also accepts negative indexes, taking elements from the back of
the list, aka `get (-1)`

is the last element of the list and `get (-2)`

the
second to last.
Both positive and negative indexes are subject to boundary checks.

`>>>`

Just 3`get -1 [1, 2, 3]`

`>>>`

Nothing`get -4 [1, 2, 3]`

For infinite lists using negative indexes is _|_ (does not terminate). Positive indexes do however do work with infinite lists.

# Modifying lists

slice :: Int -> Int -> [α] -> [α] Source

`slice i j`

extracts a sublist from index i up to, but not including, j.

This function also accepts negative indexes which, again, are _|_ for infinite lists.

`>>>`

[2, 3]`slice 1 3 [1, 2, 3, 4, 5]`

The index rules are the same as with `get`

.

# Tuple conversions

"to**N**Tuple" functions match whether a list contains *only* **N**
elements yielding an **N**-`Tuple`

containing those elements.

This can for example also be used to extract elements from a section of the
list as a `Tuple`

like so:

to3Tuple . take 3

to1Value :: [α] -> Maybe α Source

Completeness function that converts a singleton list into its only contained value.

This function is the single value version of the "to**N**Tuple" function family.

# Zipping lists

Zipping functions that do not stop when the shorter lists expire but when the longer lists do.

## Zipping to Maybe

The fillZip**N** function family takes **N** lists and returns a list of
**N**-tuples.

Unlike `zip`

`fillZip`

does not stop when one of the lists is empty, but
keeps going inserting `Nothing`

for the missing values in the shorter lists.

fillZip5 :: [α] -> [β] -> [γ] -> [δ] -> [ζ] -> [(Maybe α, Maybe β, Maybe γ, Maybe δ, Maybe ζ)] Source

## Zipping Monoids

The monoidFillZip**N** function family takes **N** lists and returns a
list of **N**-tuples.

Unlike `zip`

, `monoidFillZip`

does not stop when one of the lists is empty,
but keeps going inserting `mempty`

for the missing values in the shorter
lists.

monoidFillZip :: (Monoid α, Monoid β) => [α] -> [β] -> [(α, β)] Source

Alias for `monoidFillZip2`

.

monoidFillZip2 :: (Monoid α, Monoid β) => [α] -> [β] -> [(α, β)] Source

monoidFillZip3 :: (Monoid α, Monoid β, Monoid γ) => [α] -> [β] -> [γ] -> [(α, β, γ)] Source