Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

Special takes and drops on lists.

# Documentation

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

`takeEvery n xs`

is a list of every `n`

th element of `xs`

.

**Precondition:** `n`

must be positive.

`>>>`

[3, 6, 9]`takeEvery 3 [1..10]`

`>>>`

True`takeEvery 1 [1..10] == [1..10]`

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

`dropEvery n xs`

is a list of every `n`

th element of `xs`

.

**Precondition:** `n`

must be positive.

`>>>`

[1, 2, 4, 5, 7, 8, 10]`dropEvery 3 [1..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.

`>>>`

[1, 2, 3, 4, 5]`takeUntil (== 5) [1..]`

`>>>`

[3, 2, 1]`takeUntil (== 7) [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.

`>>>`

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

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

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

`>>>`

[6, 7, 8, 9, 10]`dropUntil (== 5) [1..10]`

`>>>`

[]`dropUntil (< 0) [1, 2, 3]`

`>>>`

[]`dropUntil undefined []`

Note that `dropUntil`

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

`>>>`

[]`dropUntil undefined [undefined]`