From 5fac43d7537c84cb2874e1d8c16d93212033a796 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 31 May 2017 15:14:21 +0300 Subject: [PATCH] (refs #7259) Added Iterator.filter and MSet.filterInPlace Change-Id: If8d9ff797a2747346e42e3242da292dc78784e9b --- bundles/org.simantics.scl.runtime/scl/Iterator.scl | 13 +++++++++++++ bundles/org.simantics.scl.runtime/scl/MSet.scl | 3 +++ 2 files changed, 16 insertions(+) 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) -- 2.47.1