HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleutility-ht-0.0.17.2Haskell98

Data.List.Reverse.StrictElement

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.

  • 3 values
Example8 expressions
import Test.Utility (forAllPredicates, defined)import qualified Data.List.Reverse.StrictElement as Revimport qualified Data.List.Match as Matchimport qualified Data.List as Listimport Data.Tuple.HT (mapPair, swap)_suppressUnusedImportWarning :: (a -> Bool) -> [a] -> [a]_suppressUnusedImportWarning = Data.List.Reverse.StrictElement.dropWhile
valuedropWhile :: (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.

Property
forAllPredicates $ \p xs -> Rev.dropWhile p xs == reverse (List.dropWhile p (reverse xs))
Property
\x xs pad -> defined $ Match.take (pad::[()]) $ Rev.dropWhile ((x::Char)/=) $ cycle $ x:xs
valuetakeWhile :: (a -> Bool) -> [a] -> [a]
#

Alternative version of reverse . takeWhile p . reverse.

Property
forAllPredicates $ \p xs -> Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs))
valuespan :: (a -> Bool) -> [a] -> ([a], [a])
#
Property
forAllPredicates $ \p xs -> Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs)))
Property
forAllPredicates $ \p xs -> Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs)
Property
\x xs pad -> defined $ Match.take (pad::[()]) $ fst $ Rev.span ((x::Char)/=) $ cycle $ x:xs