X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.runtime%2Fscl%2FPrelude.scl;h=21658862db66f34262c1852603872ff5f25291ef;hp=6966b4489d0652c61b8cde57fc7d185b75a2dd08;hb=c125a1755cc7c4a6241c3c5bf841c3db0ff2d658;hpb=2a8d452434358e28cb826744bc01755a46455afd diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index 6966b4489..21658862d 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -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 -> Boolean) -> [a] -> [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 -> Boolean) -> [a] -> ([a], [a]) partition p l = runProc do res1 = newArrayList