Portability | portable |
---|---|

Stability | experimental |

Maintainer | Brandon Simmons <brandon.m.simmons@gmail.com> |

Provides functions for the awkward task of dividing a list into sub-lists, based on some predicate function, or based on some integer offset (e.g. dividing a list into lists of three elements each.

We could abstract out some common patterns, but I want the code to be copy-and-pasteable. I'm hoping that this module can eventually contain the most efficient implementation possible of these functions, and would appreciate any suggestions or patches. Please also send any suggestions for other useful list-grouping functions.

Please send me any requests, bugs, or improvements to this module!

- splitEvery :: Int -> [a] -> [[a]]
- splitWith :: [Int] -> [a] -> [[a]]
- splitWithDrop :: [Int] -> [a] -> [[a]]
- breakBefore :: (a -> Bool) -> [a] -> [[a]]
- breakAfter :: (a -> Bool) -> [a] -> [[a]]
- breakDrop :: (a -> Bool) -> [a] -> [[a]]

# Grouping by integer offsets:

splitEvery :: Int -> [a] -> [[a]]Source

partitions list into sub-lists of length given by the Int:

splitWith :: [Int] -> [a] -> [[a]]Source

partitions list into lengths corresponding the list of Ints supplied. if we run out of lengths, the remaining tail is returned as last element.

splitWithDrop :: [Int] -> [a] -> [[a]]Source

same as `splitWith`

but we drop the end of our list should we run out of
integer lengths.

# Grouping by predicate:

breakBefore :: (a -> Bool) -> [a] -> [[a]]Source

partitions list before every element matching predicate:

breakAfter :: (a -> Bool) -> [a] -> [[a]]Source

partitions list after every element matching predicate: