importJava "java.util.Iterator" where data Iterator a hasNext :: Iterator a -> Boolean next :: Iterator a -> a @inline iter :: (a -> dummy) -> Iterator a -> () iter f it = loop () where loop _ = if hasNext it then do f (next it) loop () else () @inline find :: (a -> Boolean) -> Iterator a -> Maybe a find f it = loop () where loop _ = if hasNext it then let el = next it in if f el then Just el else loop () else Nothing @inline any :: (a -> Boolean) -> Iterator a -> Boolean any f it = loop () where loop _ = if hasNext it then if f (next it) then True else loop () else False @inline all :: (a -> Boolean) -> Iterator a -> Boolean all f it = loop () where loop _ = if hasNext it then if f (next it) then loop () else False else True @inline mapFirst :: (a -> Maybe b) -> Iterator a -> Maybe b mapFirst f it = loop () where loop _ = if hasNext it then match f (next it) with Nothing -> loop () r -> r else Nothing @inline foldl :: (a -> b -> a) -> a -> Iterator b -> a foldl f init it = loop init where loop cur = if hasNext it then loop (f cur (next it)) else cur @inline foldl1 :: (a -> a -> a) -> Iterator a -> a foldl1 f it = foldl f (next it) it