Class Functions
java.lang.Object
org.javimmutable.collections.util.Functions
Library of static functions that perform various operations on Iterators.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> IMap <K, V> static <K,
V> IMap <K, V> static <T> Maybe
<T> Calls func for each value in iterator and passes it to func until func returns true.static <T,
R> R Calls func for every value in iterator passing in the accumulator and each value as parameters and setting accumulator to the result.static <T,
R> R Calls func for every value in iterator from right to left (i.e.static <T> Iterator
<T> Creates a new Iterator whose values are in the reverse order of the provided Iterator.
-
Method Details
-
foldLeft
public static <T,R> R foldLeft(R accumulator, Iterator<? extends T> iterator, Func2<R, ? super T, R> func) Calls func for every value in iterator passing in the accumulator and each value as parameters and setting accumulator to the result. The final accumulator value is returned. -
foldRight
public static <T,R> R foldRight(R accumulator, Iterator<? extends T> iterator, Func2<R, ? super T, R> func) Calls func for every value in iterator from right to left (i.e. in reverse order) passing in the accumulator and each value as parameters and setting the accumulator to the result. The final accumulator value is returned. Requires 2x time compared to foldLeft() since it reverses the order of the iterator before calling the function. -
reverse
Creates a new Iterator whose values are in the reverse order of the provided Iterator. Requires O(n) time and creates an intermediate copy of the Iterator's values. -
find
Calls func for each value in iterator and passes it to func until func returns true. If func returns true the value is returned. If func never returns true an empty value is returned. -
assignAll
-
assignAll
-