Class Functions

java.lang.Object
org.javimmutable.collections.util.Functions

public final class Functions extends Object
Library of static functions that perform various operations on Iterators.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <K, V> IMap<K,V>
    assignAll(IMap<K,V> dest, Map<K,V> src)
     
    static <K, V> IMap<K,V>
    assignAll(IMap<K,V> dest, IMap<K,V> src)
     
    static <T> Maybe<T>
    find(Iterator<? extends T> iterator, Func1<? super T,Boolean> func)
    Calls func for each value in iterator and passes it to func until func returns true.
    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.
    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.
    static <T> Iterator<T>
    reverse(Iterator<? extends T> iterator)
    Creates a new Iterator whose values are in the reverse order of the provided Iterator.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static <T> Iterator<T> reverse(Iterator<? extends T> iterator)
      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

      public static <T> Maybe<T> find(Iterator<? extends T> iterator, Func1<? super T,Boolean> func)
      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

      public static <K, V> IMap<K,V> assignAll(IMap<K,V> dest, IMap<K,V> src)
    • assignAll

      public static <K, V> IMap<K,V> assignAll(IMap<K,V> dest, Map<K,V> src)