ref: aface2b31b04fff88848433758d376ce932530a6
parent: e221a88a6d60f0680a508aa6730254e71d29bb93
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Wed Sep 11 13:40:52 EDT 2024
More functions
--- a/lib/Data/List.hs
+++ b/lib/Data/List.hs
@@ -10,8 +10,8 @@
mapAccumL, mapAccumR,
iterate, iterate', repeat, replicate, cycle,
unfoldr,
- take, drop, splitAt, takeWhile, dropWhile, dropWhileEnd, span, break, splitWith,
- stripPrefix, group, inits, tails,
+ take, drop, splitAt, takeWhile, takeWhileEnd, dropWhile, dropWhileEnd, span, break, splitWith,
+ stripPrefix, stripSuffix, group, inits, tails,
isPrefixOf, isSuffixOf, isInfixOf, isSubsequenceOf,
elem, notElem, lookup,
find, filter, partition,
@@ -312,6 +312,12 @@
stripPrefixBy eq (c:cs) (d:ds) | eq c d = stripPrefixBy eq cs ds
| otherwise = Nothing
+stripSuffix :: forall a . Eq a => [a] -> [a] -> Maybe [a]
+stripSuffix s t =
+ case stripPrefix (reverse s) (reverse t) of
+ Nothing -> Nothing
+ Just x -> Just (reverse x)
+
isPrefixOf :: forall a . Eq a => [a] -> [a] -> Bool
isPrefixOf = isPrefixOfBy (==)
@@ -349,6 +355,9 @@
x : takeWhile p xs
else
[]
+
+takeWhileEnd :: forall a . (a -> Bool) -> [a] -> [a]
+takeWhileEnd p = reverse . takeWhile p . reverse
dropWhile :: forall a . (a -> Bool) -> [a] -> [a]
dropWhile _ [] = []
--
⑨