dropWhileEnd

The dropWhileEnd function drops the largest suffix of a list in which the given predicate holds for all elements.

Laziness

This function is lazy in spine, but strict in elements, which makes it different from reverse . dropWhile p . reverse, which is strict in spine, but lazy in elements. For instance:
>>> take 1 (dropWhileEnd (< 0) (1 : undefined))
[1]
>>> take 1 (reverse $ dropWhile (< 0) $ reverse (1 : undefined))
*** Exception: Prelude.undefined
but on the other hand
>>> last (dropWhileEnd (< 0) [undefined, 1])
*** Exception: Prelude.undefined
>>> last (reverse $ dropWhile (< 0) $ reverse [undefined, 1])
1

Examples

>>> dropWhileEnd isSpace "foo\n"
"foo"
>>> dropWhileEnd isSpace "foo bar"
"foo bar"

>>> dropWhileEnd (> 10) [1..20]
[1,2,3,4,5,6,7,8,9,10]
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
dropWhileEnd p xs returns the prefix remaining after takeWhileEnd p xs.
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
>>> {-# LANGUAGE OverloadedLists #-)

>>> dropWhileEnd even [1,2,3,4,6]
[1,2,3]
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
O(n) dropWhileEnd p t returns the prefix remaining after dropping characters that satisfy the predicate p from the end of t. Examples:
>>> dropWhileEnd (=='.') "foo..."
"foo"
O(n) dropWhileEnd p t returns the prefix remaining after dropping characters that satisfy the predicate p from the end of t. Examples:
dropWhileEnd (=='.') "foo..." == "foo"
The dropWhileEnd function drops the largest suffix of a list in which the given predicate holds for all elements. For example:
>>> dropWhileEnd isSpace "foo\n"
"foo"
>>> dropWhileEnd isSpace "foo bar"
"foo bar"
dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined
O(n) dropWhileEnd p t returns the prefix remaining after dropping characters that satisfy the predicate p from the end of t. Subject to fusion. Examples:
>>> dropWhileEnd (=='.') "foo..."
"foo"
Remove longest suffix satisfying given predicate.
dropWhileEnd p t == fst (spanEnd p t)
>>> dropWhileEnd (>= 'c') "abcdabcd"
"abcdab"
O(n) dropWhileEnd p b returns the prefix remaining after dropping characters that satisfy the predicate p from the end of t.
Drops all elements from the end of the list that satisfy the function.
O(n) dropWhileEnd p t returns the prefix remaining after dropping characters that fail the predicate p from the end of t. Subject to fusion. Examples:
dropWhileEnd (=='.') "foo..." == "foo"
As dropWhile but drops from the end instead.
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder. dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
dropWhileEndLE p is equivalent to reverse . dropWhile p . reverse, but quite a bit faster. The difference between "Data.List.dropWhileEnd" and this version is that the one in Data.List is strict in elements, but spine-lazy, while this one is spine-strict but lazy in elements. That's what LE stands for - "lazy in elements". Example:
>>> safeTail $ Data.List.dropWhileEnd (<3) [undefined, 5, 4, 3, 2, 1]
*** Exception: Prelude.undefined
...
>>> safeTail $ dropWhileEndLE (<3) [undefined, 5, 4, 3, 2, 1]
[5,4,3]
>>> take 3 $ Data.List.dropWhileEnd (<3) [5, 4, 3, 2, 1, undefined]
[5,4,3]
>>> take 3 $ dropWhileEndLE (<3) [5, 4, 3, 2, 1, undefined]
*** Exception: Prelude.undefined
...
A version of dropWhileEnd but with different strictness properties. The function dropWhileEnd can be used on an infinite list and tests the property on each character. In contrast, dropWhileEnd' is strict in the spine of the list but only tests the trailing suffix. This version usually outperforms dropWhileEnd if the list is short or the test is expensive. Note the tests below cover both the prime and non-prime variants.
dropWhileEnd  isSpace "ab cde  " == "ab cde"
dropWhileEnd' isSpace "ab cde  " == "ab cde"
last (dropWhileEnd  even [undefined,3]) == undefined
last (dropWhileEnd' even [undefined,3]) == 3
head (dropWhileEnd  even (3:undefined)) == 3
head (dropWhileEnd' even (3:undefined)) == undefined
Throws an exception the Char argument is non-ascii.
A monadic version of dropWhileEnd :: (a -> Bool) -> [a] -> m [a]. Effects happen starting at the end of the list until p becomes false.