From: Hannu Niemistö Date: Wed, 31 May 2017 12:14:21 +0000 (+0300) Subject: (refs #7259) Added Iterator.filter and MSet.filterInPlace X-Git-Tag: v1.29.0~6^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F81%2F581%2F1;p=simantics%2Fplatform.git (refs #7259) Added Iterator.filter and MSet.filterInPlace Change-Id: If8d9ff797a2747346e42e3242da292dc78784e9b --- diff --git a/bundles/org.simantics.scl.runtime/scl/Iterator.scl b/bundles/org.simantics.scl.runtime/scl/Iterator.scl index be7fb90e0..19e51a0d5 100644 --- a/bundles/org.simantics.scl.runtime/scl/Iterator.scl +++ b/bundles/org.simantics.scl.runtime/scl/Iterator.scl @@ -27,6 +27,19 @@ iterB f it = loop () else False else True +@inline +filter :: (a -> Boolean) -> T a -> () +filter f it = loop () + where + loop _ = + if hasNext it + then do + if f (next it) + then () + else remove it + loop () + else () + @inline mapFirst :: (a -> Maybe b) -> T a -> Maybe b mapFirst f it = loop () diff --git a/bundles/org.simantics.scl.runtime/scl/MSet.scl b/bundles/org.simantics.scl.runtime/scl/MSet.scl index 9f543101f..3e280d6b5 100644 --- a/bundles/org.simantics.scl.runtime/scl/MSet.scl +++ b/bundles/org.simantics.scl.runtime/scl/MSet.scl @@ -80,3 +80,6 @@ concatMap f s = result all :: (a -> Boolean) -> T a -> Boolean all f s = Iterator.iterB f (iterator s) + +filterInPlace :: (a -> Boolean) -> T a -> () +filterInPlace p s = Iterator.filter p (iterator s)