list-filter-0.1.0.0: Special takes and drops on lists

Safe HaskellSafe
LanguageHaskell2010

Data.List.Filter

Description

Special takes and drops on lists.

Synopsis

Documentation

takeEvery :: Int -> [a] -> [a] Source #

takeEvery n xs is a list of every nth element of xs.

Precondition: n must be positive.

>>> takeEvery 3 [1..10]
[3, 6, 9]
>>> takeEvery 1 [1..10] == [1..10]
True

dropEvery :: Int -> [a] -> [a] Source #

dropEvery n xs is a list of every nth element of xs.

Precondition: n must be positive.

>>> dropEvery 3 [1..10]
[1, 2, 4, 5, 7, 8, 10]
>>> dropEvery 1 [1..10]
[]

takeUntil :: (a -> Bool) -> [a] -> [a] Source #

Take a list until a predicate is satisfied, and include the element satisfying the predicate.

>>> takeUntil (== 5) [1..]
[1, 2, 3, 4, 5]
>>> takeUntil (== 7) [3, 2, 1]
[3, 2, 1]
>>> takeUntil undefined []
[]

Note that takeUntil on a nonempty list must always yield the first element, and the implementation is lazy enough to take advantage of this fact.

>>> head (takeUntil undefined [1..])
1

dropUntil :: (a -> Bool) -> [a] -> [a] Source #

Drop a list until a predicate is satisfied, and include the element satisfying the predicate.

>>> dropUntil (== 5) [1..10]
[5, 6, 7, 8, 9, 10]
>>> dropUntil (< 0) [1, 2, 3]
[]
>>> dropUntil undefined []
[]