iterate


Description:

public static Seq<G> iterate<G> (owned G seed, owned Predicate<G> pred, owned MapFunc<G,G> next, TaskEnv? env = null)

Creates a new sequential seq, which each element is generated by the given next function applied to the previous element, and the initial element is the seed. The seq terminates when pred(item) returns false.

The returned seq is similar to the for-loop below:

for (G item = seed; pred(item); item = next(item)) {
// Operations on the item.
}

Parameters:

seed

the initial element

pred

a predicate function to determine when the seq terminates

next

a mapping function to produce a new element by applying to the previous element

env

a task environment. If not specified, TaskEnv.get_common_task_env is used.

Returns:

the result seq