Safe Haskell | None |
---|

`AUTHOR`

- Dr. Alistair Ward
`DESCRIPTION`

- Miscellaneous polymorphic list-operations.

- type ChunkLength = Int
- type Matches a = a -> a -> Bool
- chunk :: ChunkLength -> [a] -> [[a]]
- excise :: Int -> [a] -> [a]
- equalityBy :: Eq b => (a -> b) -> Matches a
- findConvergence :: Eq a => [a] -> a
- findConvergenceBy :: Matches a -> [a] -> a
- linearise :: [(a, a)] -> [a]
- merge :: Ord a => [a] -> [a] -> [a]
- mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
- nub' :: Ord a => [a] -> [a]
- permutations :: [[a]] -> [[a]]
- permutationsBy :: Matches a -> [[a]] -> [[a]]
- takeUntil :: (a -> Bool) -> [a] -> [a]
- showListWith :: (Show token, Show element) => (token, token, token) -> [element] -> ShowS

# Types

## Type-synonyms

type ChunkLength = IntSource

The length of the chunks into which a list is split.

type Matches a = a -> a -> BoolSource

The type of function required by `findConvergenceBy`

, `permutationsBy`

.

# Functions

:: ChunkLength | |

-> [a] | The polymorphic input list to be chunked. |

-> [[a]] |

- Splits a list into chunks of the specified length.
- The last chunk will be shorter, if the chunk-length isn't an aliquot part of the input list-length.
- If the chunk-length is zero, the resulting list will be an infinite sequence of null lists.
- CAVEAT: a similar function is available in the module
*Data.List.Split*, though this one checks for`(chunkLength < 0)`

.

:: Int | The index. |

-> [a] | The polymorphic input list. |

-> [a] | The same list, with the indexed element removed. |

Remove the single indexed element from the list.

equalityBy :: Eq b => (a -> b) -> Matches aSource

A convenient way to compose the `Matches`

-function required by `findConvergenceBy`

& `permutationsBy`

.

findConvergence :: Eq a => [a] -> aSource

A specific instance of `findConvergenceBy`

.

findConvergenceBy :: Matches a -> [a] -> aSource

Take the first element from the (potentially infinite) list, which matches the subsequent element, according to the specified function.

mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]Source

- Merge two sorted lists, according to the specified order, to product a single sorted list.
- The merge-process is
*stable*, in that where items from each list are equal, they remain in the original order. - CAVEAT: duplicates are preserved.

permutations :: [[a]] -> [[a]]Source

- The list of all permutations, generated by selecting any one datum from each sub-list in turn, from the specified list of lists.
- A specific instance of
`permutationsBy`

, in which no filtering of subsequent lists is performed after each item is selected. - NB: differs from
`permutations`

, which selects items from a single input list.

permutationsBy :: Matches a -> [[a]] -> [[a]]Source

:: (a -> Bool) | Predicate, used to determine the last item taken. |

-> [a] | The polymorphic input list. |

-> [a] |

- Take until the specified predicate is satisfied;
*including*the item which satisfied it. - NB:
`takeWhile (not . test)`

would return one fewer item.