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.
>>>
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 n
th 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