]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Java/Collection.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Java / Collection.scl
1 import "JavaBuiltin" as Java
2 import "Java/Iterator" as Iterator
3
4 importJava "java.util.Collection" where
5     data Collection a
6     
7     contains :: Collection a -> a -> Boolean
8     isEmpty :: Collection a -> Boolean
9     size :: Collection a -> Integer
10     @private
11     iterator :: Collection a -> <Proc> Iterator.Iterator a
12
13 @inline
14 iter :: (a -> <e> dummy) -> Collection a -> <e> ()
15 iter f c = runProc (Iterator.iter f (iterator c))
16
17 @inline
18 any :: (a -> <e> Boolean) -> Collection a -> <e> Boolean
19 any f c = runProc (Iterator.any f (iterator c))
20
21 @inline
22 all :: (a -> <e> Boolean) -> Collection a -> <e> Boolean
23 all f c = runProc (Iterator.all f (iterator c))
24
25 @inline
26 foldl :: (a -> b -> <e> a) -> a -> Collection b -> <e> a
27 foldl f i c = runProc (Iterator.foldl f i (iterator c))
28
29 @inline
30 foldl1 :: (a -> a -> <e> a) -> Collection a -> <e> a
31 foldl1 f c = runProc (Iterator.foldl1 f (iterator c))
32
33 @inline
34 mapFirst :: (a -> <e> Maybe b) -> Collection a -> <e> Maybe b
35 mapFirst f c = runProc (Iterator.mapFirst f (iterator c))
36
37 @inline
38 find :: (a -> <e> Boolean) -> Collection a -> <e> Maybe a
39 find f c = runProc (Iterator.find f (iterator c))
40
41 @inline
42 uniqueElement :: Collection a -> a
43 uniqueElement c = if Java.icmpeq (size c) 1
44                   then runProc (Iterator.next (iterator c))
45                   else fail "Collection is not a singleton."