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

Safe HaskellSafe
LanguageHaskell98

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

Documentation

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

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] Source #

Alternative version of reverse . takeWhile p . reverse.

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

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