iterate
description
Returns a function which iterate over an Iterable
by calling its next method every time it is called. iterate is rarely useful by itself. However, it can be extremely useful when trying to iterate simultaneously over multiple iterables to combine them.
examples
basic example
Here, we simply get an Iterator
from an array by calling iterate
on it. Each call to the iterator will return the value of the next item in the Iterable
.
iterating simultaneously over two collections
Let's say we have an array of characters, characters
, and another one, isGood
, which indicates if each character is indeed good. We need to filter the characters to keep only the good guys, so we need to iterate simultaneously over the two collections. Let's get an Iterator
out of our isGood
array by calling iterate
on it. This will be our predicate function: each time it will be called by filter
while iterating over our characters
array, it will return the next value from isGood
, indicating if the current character is one the good guys.
Last updated