]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
New method to Prelude: indexSet 33/1733/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 25 Apr 2018 12:03:16 +0000 (15:03 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 25 Apr 2018 14:17:39 +0000 (17:17 +0300)
Change-Id: I06affe3386f014ae098c31416503fd941f3c7d36

bundles/org.simantics.scl.runtime/scl/Prelude.scl
bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/Lists.java

index d5d2788285d45a30c815a303be8937dd5f60ad68..32582affa867947fbac5167b94c4d8919c0bd91c 100644 (file)
@@ -1965,6 +1965,11 @@ importJava "org.simantics.scl.runtime.Lists" where
     """
     index :: [(a,b)] -> a -> Maybe b
     
+    """
+    Given a list of elements, the function produces its characteristic function.
+    """
+    indexSet :: [a] -> a -> Boolean
+    
     """
     Given a list of values and a function computing a key for each value, the function produces a function that finds a value
     effeciently for the given key.
index 5259ce6315a38b5b9b1ab64f94ce452cb82930ca..99c19d6b951cbe26c140d13b3ed8dcbc2aefbf06 100644 (file)
@@ -240,7 +240,19 @@ public class Lists {
             }
         };
     }
-    
+
+    public static Function indexSet(List<Object> l) {
+        THashSet set = new THashSet(l.size());
+        for(Object obj : l)
+            set.add(obj);
+        return new FunctionImpl1<Object,Object>() {
+            @Override
+            public Object apply(Object p0) {
+                return set.contains(p0);
+            }
+        };
+    }
+
     public static Function indexBy(Function f, List l) {
         THashMap map = new THashMap(l.size());
         for(Object o : l)