shithub: MicroHs

Download patch

ref: 21f8feab14279b9b03adee3e774f47f4f76d0ded
parent: 0e5ca6a53d99afd8d4990ab6340da4e77f1079d4
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Wed Sep 11 12:06:20 EDT 2024

Add splitWith function

--- a/lib/Data/List.hs
+++ b/lib/Data/List.hs
@@ -10,7 +10,7 @@
   mapAccumL, mapAccumR,
   iterate, iterate', repeat, replicate, cycle,
   unfoldr,
-  take, drop, splitAt, takeWhile, dropWhile, dropWhileEnd, span, break,
+  take, drop, splitAt, takeWhile, dropWhile, dropWhileEnd, span, break, splitWith,
   stripPrefix, group, inits, tails,
   isPrefixOf, isSuffixOf, isInfixOf, isSubsequenceOf,
   elem, notElem, lookup,
@@ -369,6 +369,14 @@
     rec r [] = (reverse r, [])
     rec r (x:xs) = if p x then rec (x:r) xs else (reverse (x:r), xs)
   in rec []
+
+splitWith :: forall a . (a -> Bool) -> [a] -> [[a]]
+splitWith p =
+  let
+    rec r s  []                = reverse (reverse s : r)
+    rec r s (x:xs) | p x       = rec (reverse s : r) []      xs
+                   | otherwise = rec              r  (x : s) xs
+  in rec [] []
 
 head :: forall a . [a] -> a
 head [] = error "head"
--