Module Java/Iterator

This module is undocumented. This is a list of its definitions.

all :: (a -> <b> Boolean) -> Iterator a -> <Proc,b> Boolean

Returns True if all remaining values of the iterator satisfy the given predicate. Stops at the first rejected value.

any :: (a -> <b> Boolean) -> Iterator a -> <Proc,b> Boolean

Returns True if at least one remaining value of the iterator satisfies the given predicate. Stops at the first accepted value.

find :: (a -> <b> Boolean) -> Iterator a -> <Proc,b> Maybe a

The first remaining value of the iterator that satisfies the given predicate, or Nothing if there is none.

The search consumes the iterator up to and including the value it returns, so what is left of the iterator afterwards are the values after the match. See foldl1 for an example.

foldl :: (a -> b -> <c> a) -> a -> Iterator b -> <Proc,c> a

Folds over the remaining values of the iterator starting with the given initial value.

foldl1 :: (a -> a -> <b> a) -> Iterator a -> <Proc,b> a

Like foldl, but uses the first value of the iterator as the initial value.

There is no initial value to fall back on, so foldl1 fails on an iterator that has no values left. Use foldl with an explicit initial value unless the iterator is known to be non-empty.

Example:

> import "Java/Iterator" as Iterator
> import "Iterator" as SCLIterator
> import "JavaBuiltin" as Java
> src = Java.unsafeCoerce [1, 2, 3, 4] :: SCLIterator.Iterable Integer
> it = Java.unsafeCoerce (SCLIterator.iterator src) :: Iterator.Iterator Integer
> Iterator.find (\x -> x > 1) it
Just 2
> Iterator.foldl1 (+) it
7

The two coercions are only how the example gets hold of an iterator: an SCL list is a Java Iterable at run time and the module Iterator wraps the same Java iterator type as this module. The result is 7 and not 10 because find already consumed the values 1 and 2, so foldl1 folds 3 and 4, starting from

hasNext :: Iterator a -> <Proc> Boolean

Returns True if the iterator has more values.

iter :: (a -> <c> b) -> Iterator a -> <Proc,c> ()

Calls the given function with all remaining values of the iterator.

mapFirst :: (a -> <c> Maybe b) -> Iterator a -> <Proc,c> Maybe b

Applies the given function to the remaining values of the iterator until it returns Just and returns that result. Returns Nothing if the function returns Nothing for all of them.

It is a search and a map in one, and like find it consumes the iterator only up to and including the value it accepted. See Iterator.mapFirst for a worked example; this is the same function on the same Java type.