Data.List.Reverse.StrictElement

utility-ht-0.0.12: Various small helper functions for Lists, Maybes, Tuples, Functions

Safe Haskell | Safe
Language | Haskell98

Data.List.Reverse.StrictElement

Description

The functions in this module process the list formally from the end. Actually they traverse the list from the start and check every element. This way they are strict in the elements and lazy in the list spline. Thus you can apply them to infinite lists. Use these functions if the list is long or the test is cheap.

Synopsis

- dropWhile :: (a -> Bool) -> [a] -> [a]
- takeWhile :: (a -> Bool) -> [a] -> [a]
- span :: (a -> Bool) -> [a] -> ([a], [a])

# Documentation

dropWhile :: (a -> Bool) -> [a] -> [a] #

Remove the longest suffix of elements satisfying p. In contrast to `reverse . dropWhile p . reverse` this works for infinite lists, too.

takeWhile :: (a -> Bool) -> [a] -> [a] #

Alternative version of `reverse . takeWhile p . reverse`.

span :: (a -> Bool) -> [a] -> ([a], [a]) #

    span p xs == (dropWhile p xs, takeWhile p xs)