X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.scl.runtime%2Fscl%2FMMap.scl;fp=bundles%2Forg.simantics.scl.runtime%2Fscl%2FMMap.scl;h=085728c5830d14db6f991dca5a0c4b7a623d69a4;hb=8cab2461c7f244ac8fabf2c7e61f0753dab68d00;hp=18e5866c080c05d35a6598c16e5382b63baa1a3f;hpb=ba07153e79390fea754342c51a1a669add711d95;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.runtime/scl/MMap.scl b/bundles/org.simantics.scl.runtime/scl/MMap.scl index 18e5866c0..085728c58 100644 --- a/bundles/org.simantics.scl.runtime/scl/MMap.scl +++ b/bundles/org.simantics.scl.runtime/scl/MMap.scl @@ -35,6 +35,15 @@ importJava "java.util.Map" where remove :: T a b -> a -> (Maybe b) clear :: T a b -> () +@inline +getOrCreate :: T a b -> (a -> b) -> a -> b +getOrCreate m f k = match get m k with + Just v -> v + Nothing -> do + v = f k + put m k v + v + @inline iter :: (a -> b -> ()) -> T a b -> () iter f m = MSet.iter (\entry -> f (keyOf entry) (valueOf entry)) (entrySet m)