list-grouping-0.1: Functions for grouping a list into sublists

Portabilityportable
Stabilityexperimental
MaintainerBrandon Simmons <brandon.m.simmons@gmail.com>

Data.List.Grouping

Contents

Description

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!

Synopsis

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:

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

partitions the list at the points matching predicate, dropping those elements that match.