From: Hannu Niemistö Date: Wed, 3 Jan 2018 11:09:24 +0000 (+0200) Subject: Added a new function pmap to Async module X-Git-Tag: v1.43.0~136^2~641 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c67ea430c37864915660dad647b086bfa29c7491;p=simantics%2Fplatform.git Added a new function pmap to Async module refs #7703 Change-Id: I848203393d115a0c8f9bbbfbf80e47f35f17616d --- diff --git a/bundles/org.simantics.scl.runtime/scl/Async.scl b/bundles/org.simantics.scl.runtime/scl/Async.scl index c47f457ef..9ff397f19 100644 --- a/bundles/org.simantics.scl.runtime/scl/Async.scl +++ b/bundles/org.simantics.scl.runtime/scl/Async.scl @@ -1,2 +1,3 @@ importJava "org.simantics.scl.runtime.utils.AsyncUtils" where - runAsync :: ( a) -> () \ No newline at end of file + runAsync :: ( a) -> () + pmap :: (a -> b) -> [a] -> [b] diff --git a/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java index 29886f21e..3392d461c 100644 --- a/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java +++ b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java @@ -2,6 +2,8 @@ package org.simantics.scl.runtime.utils; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Arrays; +import java.util.List; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function; @@ -27,4 +29,8 @@ public class AsyncUtils { } }.start(); } + + public static List pmap(Function f, List l) { + return Arrays.asList(l.parallelStream().map(a -> f.apply(a)).toArray()); + } }