]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7259) Added Iterator.filter and MSet.filterInPlace"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 31 May 2017 12:49:02 +0000 (15:49 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Wed, 31 May 2017 12:49:02 +0000 (15:49 +0300)
bundles/org.simantics.scl.runtime/scl/Iterator.scl
bundles/org.simantics.scl.runtime/scl/MSet.scl

index be7fb90e06e7f7517486275bdfc7614b79a3551c..19e51a0d5836d23cb2447daabdb1d2093e6d093a 100644 (file)
@@ -27,6 +27,19 @@ iterB f it = loop ()
              else False
         else True
 
+@inline
+filter :: (a -> <e> Boolean) -> T a -> <Proc,e> ()
+filter f it = loop ()
+  where
+    loop _ = 
+        if hasNext it
+        then do
+            if f (next it)
+            then ()
+            else remove it
+            loop ()
+        else ()
+
 @inline
 mapFirst :: (a -> <e> Maybe b) -> T a -> <Proc,e> Maybe b
 mapFirst f it = loop ()
index 9f543101fd50ca8d9555f15118327bf51c72e36d..3e280d6b5ca4758d8a99f864419ec60d731a793e 100644 (file)
@@ -80,3 +80,6 @@ concatMap f s = result
 
 all :: (a -> <e> Boolean) -> T a -> <e,Proc> Boolean
 all f s = Iterator.iterB f (iterator s) 
+
+filterInPlace :: (a -> <e> Boolean) -> T a -> <e,Proc> ()
+filterInPlace p s = Iterator.filter p (iterator s)