]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Prelude.scl
Merge commit '53059ca'
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Prelude.scl
index 6966b4489d0652c61b8cde57fc7d185b75a2dd08..21658862db66f34262c1852603872ff5f25291ef 100644 (file)
@@ -1879,6 +1879,17 @@ maybeToList :: Maybe a -> [a]
 maybeToList (Just a) = [a]
 maybeToList _ = [] 
 
+"""
+`takeWhile p l`, returns the longest prefix (possibly empty) of list `l` of elements that satisfy `p`
+"""
+takeWhile :: (a -> <e> Boolean) -> [a] -> <e> [a]
+takeWhile f l = loop 0 
+  where
+    len = length l
+    loop i | i == len  = l
+           | f (l!i)   = loop (i+1)
+           | otherwise = take i l
+
 partition :: (a -> <e> Boolean) -> [a] -> <e> ([a], [a])
 partition p l = runProc do
     res1 = newArrayList