ref: eeca3858929746ef5c5648756fac99f930cd859b
parent: d016abf2c95fda1200fd5f4aae3d9e9546f2e059
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sun Oct 22 15:36:21 EDT 2023
More Eq functions.
--- a/lib/Data/List.hs
+++ b/lib/Data/List.hs
@@ -145,11 +145,17 @@
case unzip3 xyzs of
(xs, ys, zs) -> (x:xs, y:ys, z:zs)
+stripPrefix :: forall a . Eq a => [a] -> [a] -> Maybe [a]
+stripPrefix = stripPrefixBy (==)
+
stripPrefixBy :: forall a . (a -> a -> Bool) -> [a] -> [a] -> Maybe [a]
stripPrefixBy eq [] s = Just s
stripPrefixBy eq (c:cs) [] = Nothing
stripPrefixBy eq (c:cs) (d:ds) | eq c d = stripPrefixBy eq cs ds
| otherwise = Nothing
+
+isPrefixOf :: forall a . Eq a => [a] -> [a] -> Bool
+isPrefixOf = isPrefixOfBy (==)
isPrefixOfBy :: forall a . (a -> a -> Bool) -> [a] -> [a] -> Bool
isPrefixOfBy _ [] _ = True
--
⑨