From c67ea430c37864915660dad647b086bfa29c7491 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 3 Jan 2018 13:09:24 +0200 Subject: [PATCH] Added a new function pmap to Async module refs #7703 Change-Id: I848203393d115a0c8f9bbbfbf80e47f35f17616d --- bundles/org.simantics.scl.runtime/scl/Async.scl | 3 ++- .../src/org/simantics/scl/runtime/utils/AsyncUtils.java | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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()); + } } -- 2.47.1