org.javimmutable.collections.util
Class Functions

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

public final class Functions
extends Object

Library of static functions that perform various operations on Cursors.


Method Summary
static
<K,V> JImmutableMap<K,V>
assignAll(JImmutableMap<K,V> dest, JImmutableMap<K,V> src)
           
static
<K,V> JImmutableMap<K,V>
assignAll(JImmutableMap<K,V> dest, Map<K,V> src)
           
static
<T,R,A extends Insertable<R>>
A
collectAll(Cursor<? extends T> cursor, A list, Func1<? super T,R> func)
          Calls func for every value in cursor and adds each value returned by func to a list.
static
<T,R,A extends Insertable<R>>
A
collectSome(Cursor<? extends T> cursor, A list, Func1<? super T,Holder<R>> func)
          Calls func for every value in cursor and adds each value for which func returns a non-empty Holder to a list.
static
<T> Iterable<T>
each(Cursor<T> cursor)
          Returns an Iterable that can be used to navigate each element in the specified Cursor.
static
<T> Iterable<T>
each(Cursorable<T> cursorable)
          Returns an Iterable that can be used to navigate each element in the specified Cursorable.
static
<T> Holder<T>
find(Cursor<? extends T> cursor, Func1<? super T,Boolean> func)
          Calls func for each value in cursor and passes it to func until func returns true.
static
<T,R> R
foldLeft(R accumulator, Cursor<? extends T> cursor, Func2<R,? super T,R> func)
          Calls func for every value in cursor passing in the accumulator and each value as parameters and setting accumulator to the result.
static
<T,R> R
foldRight(R accumulator, Cursor<? extends T> cursor, Func2<R,? super T,R> func)
          Calls func for every value in cursor from right to left (i.e.
static
<T,A extends Insertable<T>>
A
insertAll(A addable, Cursor<? extends T> cursor)
          Add all values form the cursor to the addable.
static
<T,A extends Insertable<T>>
A
insertAll(A addable, Iterator<? extends T> iterator)
          Add all values form the iterator to the addable.
static
<T,A extends Insertable<T>>
A
insertAll(A addable, T[] values)
          Add all values form the array to the addable.
static
<T,A extends Insertable<T>>
A
reject(Cursor<? extends T> cursor, A list, Func1<? super T,Boolean> func)
          Calls func for every value in cursor and adds each value for which func returns false to a list.
static
<T> Cursor<T>
reverse(Cursor<? extends T> cursor)
          Creates a new Cursor whose values are in the reverse order of the provided Cursor.
static
<T,A extends Insertable<T>>
A
select(Cursor<? extends T> cursor, A list, Func1<? super T,Boolean> func)
          Calls func for every value in cursor and adds each value for which func returns true to a list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

foldLeft

public static <T,R> R foldLeft(R accumulator,
                               Cursor<? extends T> cursor,
                               Func2<R,? super T,R> func)
Calls func for every value in cursor passing in the accumulator and each value as parameters and setting accumulator to the result. The final accumulator value is returned.

Parameters:
accumulator -
cursor -
func -
Returns:

foldRight

public static <T,R> R foldRight(R accumulator,
                                Cursor<? extends T> cursor,
                                Func2<R,? super T,R> func)
Calls func for every value in cursor 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 cursor before calling the function.

Type Parameters:
T -
R -
Parameters:
accumulator -
func -
cursor -
Returns:

reverse

public static <T> Cursor<T> reverse(Cursor<? extends T> cursor)
Creates a new Cursor whose values are in the reverse order of the provided Cursor. Requires O(n) time and creates an intermediate copy of the Cursor's values.

Type Parameters:
T -
Parameters:
cursor -
Returns:

collectAll

public static <T,R,A extends Insertable<R>> A collectAll(Cursor<? extends T> cursor,
                                                         A list,
                                                         Func1<? super T,R> func)
Calls func for every value in cursor and adds each value returned by func to a list. Returns the resulting list.

Type Parameters:
T -
Parameters:
cursor - source of the values
func - function to transform the values
list - list to receive the values
Returns:

collectSome

public static <T,R,A extends Insertable<R>> A collectSome(Cursor<? extends T> cursor,
                                                          A list,
                                                          Func1<? super T,Holder<R>> func)
Calls func for every value in cursor and adds each value for which func returns a non-empty Holder to a list. Returns the resulting list.

Type Parameters:
T -
Parameters:
cursor - source of the values
func - function to reject the values
list - list to receive the values
Returns:

find

public static <T> Holder<T> find(Cursor<? extends T> cursor,
                                 Func1<? super T,Boolean> func)
Calls func for each value in cursor 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.

Type Parameters:
T -
Parameters:
cursor -
func -
Returns:

reject

public static <T,A extends Insertable<T>> A reject(Cursor<? extends T> cursor,
                                                   A list,
                                                   Func1<? super T,Boolean> func)
Calls func for every value in cursor and adds each value for which func returns false to a list. Returns the resulting list.

Type Parameters:
T -
Parameters:
cursor - source of the values
func - function to reject the values
list - list to receive the values
Returns:

select

public static <T,A extends Insertable<T>> A select(Cursor<? extends T> cursor,
                                                   A list,
                                                   Func1<? super T,Boolean> func)
Calls func for every value in cursor and adds each value for which func returns true to a list. Returns the resulting list.

Parameters:
cursor - source of the values
func - function to select the values
list - list to receive the values
Returns:

insertAll

public static <T,A extends Insertable<T>> A insertAll(A addable,
                                                      Iterator<? extends T> iterator)
Add all values form the iterator to the addable.

Parameters:
iterator -
Returns:

insertAll

public static <T,A extends Insertable<T>> A insertAll(A addable,
                                                      Cursor<? extends T> cursor)
Add all values form the cursor to the addable.

Parameters:
cursor -
Returns:

insertAll

public static <T,A extends Insertable<T>> A insertAll(A addable,
                                                      T[] values)
Add all values form the array to the addable.

Parameters:
values -
Returns:

assignAll

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

assignAll

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

each

public static <T> Iterable<T> each(Cursor<T> cursor)
Returns an Iterable that can be used to navigate each element in the specified Cursor. The Cursor must not have been started yet. Intended for use in java foreach loops.

Type Parameters:
T -
Parameters:
cursor -
Returns:

each

public static <T> Iterable<T> each(Cursorable<T> cursorable)
Returns an Iterable that can be used to navigate each element in the specified Cursorable. Intended for use in java foreach loops.

Type Parameters:
T -
Parameters:
cursorable -
Returns:


Copyright © 2014 Burton Computer Corporation. All rights reserved.