1 import "JavaBuiltin" as Java
2 import "Java/Iterator" as Iterator
4 importJava "java.util.Collection" where
7 contains :: Collection a -> a -> Boolean
8 isEmpty :: Collection a -> Boolean
9 size :: Collection a -> Integer
11 iterator :: Collection a -> <Proc> Iterator.Iterator a
14 iter :: (a -> <e> dummy) -> Collection a -> <e> ()
15 iter f c = runProc (Iterator.iter f (iterator c))
18 any :: (a -> <e> Boolean) -> Collection a -> <e> Boolean
19 any f c = runProc (Iterator.any f (iterator c))
22 all :: (a -> <e> Boolean) -> Collection a -> <e> Boolean
23 all f c = runProc (Iterator.all f (iterator c))
26 foldl :: (a -> b -> <e> a) -> a -> Collection b -> <e> a
27 foldl f i c = runProc (Iterator.foldl f i (iterator c))
30 foldl1 :: (a -> a -> <e> a) -> Collection a -> <e> a
31 foldl1 f c = runProc (Iterator.foldl1 f (iterator c))
34 mapFirst :: (a -> <e> Maybe b) -> Collection a -> <e> Maybe b
35 mapFirst f c = runProc (Iterator.mapFirst f (iterator c))
38 find :: (a -> <e> Boolean) -> Collection a -> <e> Maybe a
39 find f c = runProc (Iterator.find f (iterator c))
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."