jedi.functional
Class FunctionalPrimitives

java.lang.Object
  extended by jedi.functional.FunctionalPrimitives

public class FunctionalPrimitives
extends Object

I provide operations of the kind found in Functional Programming languages. This allows you to remove a great deal of clutter from production code. Ideally, you will never need to write another 'for' loop again, and a great deal of explicit conditional logic should be removable as well.

Generally, functions that transform collections (using functors or whatever) preserve the iteration order of the given collection in the result.


Method Summary
static
<T> Collection<T>
addAll(Collection<T> list, Iterable<? extends T> iterable)
          Add all the elements of an iterable to a collection.
static
<T> List<T>
append(Iterable<? extends Iterable<? extends T>> iterables)
          Append all of the elements in all of the given collections into one list.
static
<T> List<T>
append(Iterable<? extends T>... iterables)
          Append all of the elements in all of the given collections into one list.
static
<T,R> List<R>
collect(Iterable<T> items, Functor<? super T,R> functor)
          Apply functor to each element of items and return the list of results.
static
<T,R> List<R>
collect(T[] items, Functor<? super T,R> functor)
          Apply functor to each element of items and return the list of results.
static
<T,U,R> ComposeableFunctor<U,R>
curry(Functor2<T,U,R> f2, Functor0<? extends T> f0)
          Curries f2 with f0 returning a functor taking a single argument.
static
<T> List<T>
drop(int n, Iterable<T> items)
          Get all but the first n elements of items.
static
<T> List<T>
dropRight(int n, Iterable<T> items)
          Get all but the last n elements of items.
static
<T> T
first(Iterable<? extends T> collection)
          An alias for head
static
<T> T
first(Iterable<T> all, Filter<? super T> filter)
          Find the first item that matches the given filter
static
<T> Option<T>
firstOption(Iterable<T> items)
          Get the first item (in iteration order) from a collection as an Option.
static
<T> Option<T>
firstOption(Iterable<T> all, Filter<? super T> filter)
          Find the first item that matches the given filter
static
<T> T
firstOrDefault(Iterable<? extends T> all, Filter<? super T> filter, T defaultValue)
          Find the first item that matches the given filter or null if no match can be found
static
<T> T
firstOrNull(Iterable<T> all, Filter<? super T> filter)
          Find the first item that matches the given filter or null if no match can be found
static
<T,R> List<R>
flatMap(Iterable<T> iter, Functor<? super T,? extends Iterable<? extends R>> functor)
          Builds a new collection by applying a function to all elements of list and concatenating the results.
static
<T> List<T>
flatten(Iterable<? extends Iterable<T>> items)
          Given a collection of items (c1, c2, c3), each of which contains a collection i.e. (c1 = (c1_1, c1_2, ...), c2=(c2_1, c2_2, ...).
static
<T,R> List<R>
flatten(Iterable<T> items, Functor<? super T,? extends Iterable<? extends R>> functor)
          Suppose there is a collection of items (c1, c2, c3), each of which contains a collection i.e. (c1 = (c1_1, c1_2, ...), c2=(c2_1, c2_2, ...).
static
<T,Acc,InitialValue extends Acc>
Acc
fold(InitialValue initialValue, Iterable<T> collection, Functor2<Acc,? super T,Acc> functor2)
          Fold passes each item of a collection with an accumulated value to a functor.
static
<T,R,I extends R>
R
foldPowerset(I initialValue, Collection<T> all, Functor2<R,List<? super T>,R> functor2)
          Fold over all powersets of the give collection, in no particular order.
static
<T> Iterable<T>
forEach(Iterable<T> items, Command<? super T> command)
          Iterate over a collection of items applying the given command to each
static
<K,V> Map<K,List<V>>
group(Iterable<V> toGroup, Functor<? super V,K> keyFunctor)
          A synonym for partition(Iterable, Functor) Group the elements of a collection such that all elements that are mapped to the same value by a given keyFunctor are in the same group.
static
<T> boolean
hasItems(Iterable<T> iterable)
           
static
<T> T
head(Iterable<T> items)
          Get the first item (in iteration order) from a collection.
static
<T> Option<T>
headOption(Iterable<T> items)
          Get the first item (in iteration order) from a collection as an Option.
static
<T> T
headOrDefaultIfEmpty(Iterable<? extends T> items, T defaultValue)
          Get the first item (in iteration order) from a collection or defaultValue (which may be null) if the collection is empty.
static
<T> T
headOrNullIfEmpty(Iterable<T> items)
          Get the first item (in iteration order) from a collection or null if the collection is empty.
static
<T> int
indexWhere(Iterable<T> all, Filter<? super T> filter)
          Find the 0-based index of the first value of a collection satisfying the filter.
static
<T,R,I extends R>
R
inject(I initialValue, Iterable<T> collection, Functor2<R,? super T,R> functor2)
          An alias for fold.
static
<T> boolean
isEmpty(Iterable<T> iterable)
           
static String join(Iterable<?> items)
          Join, with default delimiter (empty string)
static String join(Iterable<?> items, String delimiter)
           
static String join(Object[] items, String delimiter)
          Returns a string created by converting each element of an array to a string, separated by delimiter.
static
<T> T
last(Iterable<? extends T> items)
          Get the last item (in iteration order) from a collection.
static
<T> int
lastIndexWhere(Iterable<T> all, Filter<? super T> filter)
          Find the 0-based index of the last value of a collection satisfying the filter.
static
<T> Option<T>
lastOption(Collection<? extends T> items)
          Get the last item (in iteration order) from a collection as an Option.
static
<T> T
lastOrDefaultIfEmpty(Iterable<? extends T> items, T defaultValue)
          Get the last item (in iteration order) from a collection or defaultValue (which may be null) if the collection is empty.
static
<T> T
lastOrNullIfEmpty(Iterable<? extends T> items)
           
static
<R> List<R>
listTabulate(int n, Functor<Integer,R> functor)
          Returns an n-element list.
static
<U,T extends Collection<? extends U>>
T
longest(Iterable<T> collections)
          Find the biggest collection in a collection of collections
static
<T> List<T>
makeList(int n, T fill)
          Returns an n-element list, whose elements are all the value fill.
static
<T,R> List<R>
map(List<T> list, Functor<? super T,R> functor)
           
static
<T,R> Set<R>
map(Set<T> set, Functor<? super T,R> functor)
           
static
<T> T
only(Collection<T> items)
          Return the one and only item in the given collection.
static
<T> Tuple2<List<T>,List<T>>
partition(Iterable<T> items, Filter<T> filter)
          Partition a collection of items into two sublists using the given filter.
static
<K,V> Map<K,List<V>>
partition(Iterable<V> toPartition, Functor<? super V,K> keyFunctor)
          A synonym for group(Iterable, Functor) Partition the elements of a collection such that all elements that are mapped to the same value by a given keyFunctor are in the same partition.
static
<T> T
pop(Iterable<T> items)
          Removes the last item (in iteration order) from a collection.
static
<T> Option<T>
popOption(Iterable<T> items)
          Removes the last item (in iteration order) from a collection as an Option.
static
<T> Set<List<T>>
powerset(Collection<T> all)
          Return the set of all subsets of the provided collection.
static
<T> void
powerset(Collection<T> all, Command<List<? super T>> command)
          Iterate all powersets of the give collection, in no particular order.
static
<T,U,R> List<R>
produce(Iterable<T> left, Iterable<U> right, Functor2<? super T,? super U,R> factory)
          Create the Cartesian product of two collections, using a functor as a factory of objects to represent the pair-wise products.
static
<Acc,T extends Acc>
Acc
reduce(Iterable<T> collection, Functor2<Acc,? super T,Acc> functor2)
          Reduce passes each item of a collection with an accumulated value to a functor yielding a single result.
static
<T> List<T>
reject(Iterable<T> items, Filter<? super T> filter)
          Filter a collection of items, returning only those that do not match a given filter, this is the inverse of select.
static
<T> List<T>
reverse(Iterable<T> items)
           
static
<T> List<T>
select(Iterable<T> items, Filter<? super T> filter)
          Filter a collection of items, returning only those that match a given filter, this is the inverse of reject.
static
<T> Command<T>
sequence(Command<? super T>... commands)
          Produce a single command that executes each of the given commands in sequence
static
<U,T extends Collection<? extends U>>
T
shortest(Iterable<T> collections)
          Find the shortest list in a list of lists
static List slice(int n, Iterable<List> items)
          Create a list from the nth elements of the given lists.
static List<String> split(String item, String regex)
          Create a list of string by splitting on a regex.
static
<T> List<List<T>>
tabulate(Iterable<T> list, int length)
           
static
<T> List<T>
tail(Iterable<T> items)
          Get all item's (in iteration order) from a collection except the first.
static
<T> List<T>
take(int n, Iterable<T> items)
          Get the first n elements of items.
static
<T> List<T>
takeMiddle(int start, int n, Iterable<T> items)
          Get n middle elements of an Iterable.
static
<T> List<T>
takeRight(int n, Iterable<T> items)
          Get the last n elements of an Iterable.
static List zip(Iterable<List> lists)
          Zip interleaves a collection of lists.
static
<A,B> List<Tuple2<A,B>>
zip(List<A> listA, List<B> listB)
          Zips two lists returning a List of Tuple2.
static
<T> List<Tuple2<T,Integer>>
zipWithIndex(List<T> list)
          ZipWithIndex Zips this list with its indices.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

append

public static <T> List<T> append(Iterable<? extends Iterable<? extends T>> iterables)
Append all of the elements in all of the given collections into one list. All of the elements of the first item in collections are appended first, then the items in the second collection, etc.

See Also:
append(Iterable...)

append

public static <T> List<T> append(Iterable<? extends T>... iterables)
Append all of the elements in all of the given collections into one list. All of the elements of the first item in collections are appended first, then the items in the second collection, etc. Equivalent to append(Iterable) (list(iterables)).

See Also:
append(Iterable), Coercions.list(Object...)

collect

public static <T,R> List<R> collect(Iterable<T> items,
                                    Functor<? super T,R> functor)
Apply functor to each element of items and return the list of results.

See Also:
collect(Object[],Functor)

collect

public static <T,R> List<R> collect(T[] items,
                                    Functor<? super T,R> functor)
Apply functor to each element of items and return the list of results. The iteration order of items is preserved in the returned list.

Equivalent to collect(functor, asList(items))

See Also:
collect(Iterable, Functor)

map

public static <T,R> List<R> map(List<T> list,
                                Functor<? super T,R> functor)
See Also:
collect(Iterable, Functor)

map

public static <T,R> Set<R> map(Set<T> set,
                               Functor<? super T,R> functor)
See Also:
collect(Iterable, Functor)

drop

public static <T> List<T> drop(int n,
                               Iterable<T> items)
Get all but the first n elements of items. See SRFI-1


dropRight

public static <T> List<T> dropRight(int n,
                                    Iterable<T> items)
Get all but the last n elements of items. See SRFI-1


flatten

public static <T,R> List<R> flatten(Iterable<T> items,
                                    Functor<? super T,? extends Iterable<? extends R>> functor)
Suppose there is a collection of items (c1, c2, c3), each of which contains a collection i.e. (c1 = (c1_1, c1_2, ...), c2=(c2_1, c2_2, ...). I can produce a collection containing all of the 'leaf' items applied to functor i.e.(c1_1, c1_2, ..., c2_1, c2_2)

Synonymous with flatMap(Iterable, Functor)

Equivalent to append(collect(items, functor))

Parameters:
items - The collection of items containing the collection of leaves
functor - Given an element of the 'top' collection, this can obtain the collection of 'leaf' objects to accumulate

flatten

public static <T> List<T> flatten(Iterable<? extends Iterable<T>> items)
Given a collection of items (c1, c2, c3), each of which contains a collection i.e. (c1 = (c1_1, c1_2, ...), c2=(c2_1, c2_2, ...). I produce a collection containing all of the 'leaf' items i.e.(c1_1, c1_2, ..., c2_1, c2_2).

Equivalent to flatten(Iterable, Functor) and flatMap(Iterable, Functor) with the IdentityFunctor

Parameters:
items - The collection of items containing the collection of leaves

addAll

public static <T> Collection<T> addAll(Collection<T> list,
                                       Iterable<? extends T> iterable)
Add all the elements of an iterable to a collection.


fold

public static <T,Acc,InitialValue extends Acc> Acc fold(InitialValue initialValue,
                                                        Iterable<T> collection,
                                                        Functor2<Acc,? super T,Acc> functor2)
Fold passes each item of a collection with an accumulated value to a functor.

For example, to sum the elements of a list:

           Functor2<Integer, Integer, Integer> summer = new Functor2<Integer, Integer, Integer>() {
                public Integer execute(Integer accumulator, Integer value) {
                        return accumulator + value;
                }
           };
           fold(10, summer, list(1, 2, 3, 4)) will return 20 (initial value of 10 + the sum of 1 .. 4)
 

For a more comprehensive description, see SRFI-1

Parameters:
initialValue - the initial value for the fold
collection - the collection over which to fold
functor2 - the function to apply to values of the collection collected in Acc

reduce

public static <Acc,T extends Acc> Acc reduce(Iterable<T> collection,
                                             Functor2<Acc,? super T,Acc> functor2)
Reduce passes each item of a collection with an accumulated value to a functor yielding a single result. The first value from the collection applied to the functor is used as the initial accumulator value.

For example, to sum the elements of a non-empty list:

           Functor2<Integer, Integer, Integer> summer = new Functor2<Integer, Integer, Integer>() {
                public Integer execute(Integer accumulator, Integer value) {
                        return accumulator + value;
                }
           };
           reduce(summer, list(1, 2, 3, 4)) will return 10
 

For a more comprehensive description, see SRFI-1

Parameters:
collection - the collection over which to fold
functor2 - the function to apply to values of the collection collected in Acc

forEach

public static <T> Iterable<T> forEach(Iterable<T> items,
                                      Command<? super T> command)
Iterate over a collection of items applying the given command to each


group

public static <K,V> Map<K,List<V>> group(Iterable<V> toGroup,
                                         Functor<? super V,K> keyFunctor)
A synonym for partition(Iterable, Functor) Group the elements of a collection such that all elements that are mapped to the same value by a given keyFunctor are in the same group. The groups are returned as a map in which each value is a collection of values in one group and whose key is the value returned by the keyFunctor for all items in the group.


partition

public static <K,V> Map<K,List<V>> partition(Iterable<V> toPartition,
                                             Functor<? super V,K> keyFunctor)
A synonym for group(Iterable, Functor) Partition the elements of a collection such that all elements that are mapped to the same value by a given keyFunctor are in the same partition. The groups are returned as a map in which each value is a collection of values in one partition and whose key is the value returned by the keyFunctor for all items in the group.


head

public static <T> T head(Iterable<T> items)
Get the first item (in iteration order) from a collection. The collection must contain at least one item or an AssertionError will be thrown.

Returns:
the first item in the collection
Throws:
AssertionError - if the collection is empty
See Also:
only(Collection), headOrNullIfEmpty(Iterable), headOrDefaultIfEmpty(Iterable, Object)

headOrDefaultIfEmpty

public static <T> T headOrDefaultIfEmpty(Iterable<? extends T> items,
                                         T defaultValue)
Get the first item (in iteration order) from a collection or defaultValue (which may be null) if the collection is empty.

Returns:
the first item in the collection or defaultValue if the collection is empty
See Also:
only(Collection), head(Iterable), headOrNullIfEmpty(Iterable)

headOrNullIfEmpty

public static <T> T headOrNullIfEmpty(Iterable<T> items)
Get the first item (in iteration order) from a collection or null if the collection is empty.

Returns:
the first item in the collection or null if the collection is empty
See Also:
only(Collection), head(Iterable), headOrDefaultIfEmpty(Iterable, Object)

headOption

public static <T> Option<T> headOption(Iterable<T> items)
Get the first item (in iteration order) from a collection as an Option.

Parameters:
items -
Returns:
the first item (in iteration order) from a collection as Some or None if the collection is empty.

last

public static <T> T last(Iterable<? extends T> items)
Get the last item (in iteration order) from a collection. The collection must contain at least one item or an AssertionError will be thrown.

Returns:
the last item in the collection
Throws:
AssertionError - if the collection is empty
See Also:
only(Collection), lastOrNullIfEmpty(Iterable), lastOrDefaultIfEmpty(Iterable, Object)

lastOrDefaultIfEmpty

public static <T> T lastOrDefaultIfEmpty(Iterable<? extends T> items,
                                         T defaultValue)
Get the last item (in iteration order) from a collection or defaultValue (which may be null) if the collection is empty.

Returns:
the last item in the collection or defaultValue if the collection is empty
See Also:
only(Collection), last(Iterable), lastOrNullIfEmpty(Iterable)

lastOrNullIfEmpty

public static <T> T lastOrNullIfEmpty(Iterable<? extends T> items)

lastOption

public static <T> Option<T> lastOption(Collection<? extends T> items)
Get the last item (in iteration order) from a collection as an Option.

Returns:
the last item as a Some or None if the collection is empty.

first

public static <T> T first(Iterable<? extends T> collection)
An alias for head

See Also:
head(Iterable)

first

public static <T> T first(Iterable<T> all,
                          Filter<? super T> filter)
Find the first item that matches the given filter

Returns:
The first item that matches the given filter
Throws:
AssertionError - if no match can be found

firstOrDefault

public static <T> T firstOrDefault(Iterable<? extends T> all,
                                   Filter<? super T> filter,
                                   T defaultValue)
Find the first item that matches the given filter or null if no match can be found

Returns:
The first item that matches the given filter or null if no match can be found

firstOrNull

public static <T> T firstOrNull(Iterable<T> all,
                                Filter<? super T> filter)
Find the first item that matches the given filter or null if no match can be found

Returns:
The first item that matches the given filter or null if no match can be found

firstOption

public static <T> Option<T> firstOption(Iterable<T> all,
                                        Filter<? super T> filter)
Find the first item that matches the given filter

Returns:
A Some Option on the first matching item or None if no items match

firstOption

public static <T> Option<T> firstOption(Iterable<T> items)
Get the first item (in iteration order) from a collection as an Option.

Parameters:
items -
Returns:
the first item (in iteration order) from a collection as Some or None if the collection is empty.

inject

public static <T,R,I extends R> R inject(I initialValue,
                                         Iterable<T> collection,
                                         Functor2<R,? super T,R> functor2)
An alias for fold.

See Also:
fold(Object, Iterable, Functor2)

join

public static String join(Iterable<?> items)
Join, with default delimiter (empty string)

See Also:
join(Object[], String)

join

public static String join(Iterable<?> items,
                          String delimiter)

join

public static String join(Object[] items,
                          String delimiter)
Returns a string created by converting each element of an array to a string, separated by delimiter. Emulates Array.join in Ruby.


listTabulate

public static <R> List<R> listTabulate(int n,
                                       Functor<Integer,R> functor)
Returns an n-element list. Element i of the list, where 0 <= i < n, is produced by the functor. For a more comprehensive description, see SRFI-1

Parameters:
n - the length of the list
functor - the functor taking an integer and returning an

longest

public static <U,T extends Collection<? extends U>> T longest(Iterable<T> collections)
Find the biggest collection in a collection of collections

Parameters:
collections -
Returns:
the shortest list

makeList

public static <T> List<T> makeList(int n,
                                   T fill)
Returns an n-element list, whose elements are all the value fill. For a more comprehensive description, see SRFI-1


only

public static <T> T only(Collection<T> items)
Return the one and only item in the given collection.

Returns:
the item in the collection
Throws:
AssertionError - if the collection contains less or more than one item
See Also:
head(Iterable), headOrNullIfEmpty(Iterable)

produce

public static <T,U,R> List<R> produce(Iterable<T> left,
                                      Iterable<U> right,
                                      Functor2<? super T,? super U,R> factory)
Create the Cartesian product of two collections, using a functor as a factory of objects to represent the pair-wise products.


reject

public static <T> List<T> reject(Iterable<T> items,
                                 Filter<? super T> filter)
Filter a collection of items, returning only those that do not match a given filter, this is the inverse of select.

See Also:
select(Iterable, Filter)

reverse

public static <T> List<T> reverse(Iterable<T> items)

select

public static <T> List<T> select(Iterable<T> items,
                                 Filter<? super T> filter)
Filter a collection of items, returning only those that match a given filter, this is the inverse of reject.

See Also:
reject(Iterable, Filter)

sequence

public static <T> Command<T> sequence(Command<? super T>... commands)
Produce a single command that executes each of the given commands in sequence


shortest

public static <U,T extends Collection<? extends U>> T shortest(Iterable<T> collections)
Find the shortest list in a list of lists

Parameters:
collections -
Returns:
the shortest list

hasItems

public static <T> boolean hasItems(Iterable<T> iterable)

isEmpty

public static <T> boolean isEmpty(Iterable<T> iterable)

slice

public static List slice(int n,
                         Iterable<List> items)
Create a list from the nth elements of the given lists.


split

public static List<String> split(String item,
                                 String regex)
Create a list of string by splitting on a regex.

See Also:
String.split(String)

tail

public static <T> List<T> tail(Iterable<T> items)
Get all item's (in iteration order) from a collection except the first. The collection must contain at least one item or an AssertionError will be thrown.

Returns:
all items except the first
Throws:
AssertionError - if the collection contains less or more than one item
See Also:
only(Collection), headOrNullIfEmpty(Iterable), headOrDefaultIfEmpty(Iterable, Object)

take

public static <T> List<T> take(int n,
                               Iterable<T> items)
Get the first n elements of items.

See Also:
SRFI-1

takeRight

public static <T> List<T> takeRight(int n,
                                    Iterable<T> items)
Get the last n elements of an Iterable.

See Also:
SRFI-1

takeMiddle

public static <T> List<T> takeMiddle(int start,
                                     int n,
                                     Iterable<T> items)
Get n middle elements of an Iterable.


zip

public static List zip(Iterable<List> lists)
Zip interleaves a collection of lists. If zip is passed n lists, it returns a list as long as the shortest of these lists, each element of which is an n-element list comprised of the corresponding elements from the parameter lists.

See SRFI-1

Parameters:
lists -
Returns:
zipped lists

zip

public static <A,B> List<Tuple2<A,B>> zip(List<A> listA,
                                          List<B> listB)
Zips two lists returning a List of Tuple2. The returned list's length is the smallest of listA and listB


zipWithIndex

public static <T> List<Tuple2<T,Integer>> zipWithIndex(List<T> list)
ZipWithIndex Zips this list with its indices. For example list("a", "b", "c").zipWithIndex = List(("a", 0), ("b", 1), ("c", 2)) where (x,y) is a Tuple2.

Returns:
a list of Tuple2 containing elements of list and their index in the list.

tabulate

public static <T> List<List<T>> tabulate(Iterable<T> list,
                                         int length)
Returns:
a list of lists by splitting the given list into lists of length length.

pop

public static <T> T pop(Iterable<T> items)
Removes the last item (in iteration order) from a collection. The collection must contain at least one item or an AssertionError will be thrown. Emulates Array.pop in Ruby. The original collection is unaltered.

Returns:
the last item in the collection
Throws:
AssertionError - if the collection is empty
See Also:
only(Collection), headOrNullIfEmpty(Iterable), headOrDefaultIfEmpty(Iterable, Object)

popOption

public static <T> Option<T> popOption(Iterable<T> items)
Removes the last item (in iteration order) from a collection as an Option.

Returns:
the last item in the collection as Some or None if the list is empty.

partition

public static <T> Tuple2<List<T>,List<T>> partition(Iterable<T> items,
                                                    Filter<T> filter)
Partition a collection of items into two sublists using the given filter.

Parameters:
items -
Returns:
a list whose first element as a list of items in list that pass the filter, the second item is a list of elements that did not pass the filter.

powerset

public static <T> Set<List<T>> powerset(Collection<T> all)
Return the set of all subsets of the provided collection.

For example, if all is the list ("x","y","z"), the return will be set containing 8 lists as follows:

  • () - empty set
  • ("x")
  • ("y")
  • ("z")
  • ("x","y")
  • ("x","z")
  • ("y","z")
  • ("x","y","z")

See http://en.wikipedia.org/wiki/Power_set

See Also:
powerset(Collection, Command), foldPowerset(Object, Collection, Functor2)

powerset

public static <T> void powerset(Collection<T> all,
                                Command<List<? super T>> command)
Iterate all powersets of the give collection, in no particular order.

See Also:
powerset(Collection), foldPowerset(Object, Collection, Functor2)

foldPowerset

public static <T,R,I extends R> R foldPowerset(I initialValue,
                                               Collection<T> all,
                                               Functor2<R,List<? super T>,R> functor2)
Fold over all powersets of the give collection, in no particular order.

See Also:
powerset(Collection), powerset(Collection, Command), fold(Object, Iterable, Functor2)

flatMap

public static <T,R> List<R> flatMap(Iterable<T> iter,
                                    Functor<? super T,? extends Iterable<? extends R>> functor)
Builds a new collection by applying a function to all elements of list and concatenating the results.

Synonymous with flatten(Iterable, Functor)

Parameters:
iter - the collection to map
functor - a functor yielding a collection from the application of an element from iter
Returns:
a flattened List

curry

public static <T,U,R> ComposeableFunctor<U,R> curry(Functor2<T,U,R> f2,
                                                    Functor0<? extends T> f0)
Curries f2 with f0 returning a functor taking a single argument. For example, given a Functor2, f2, that sums its integer arguments, and a Functor0, f0, that returns 3, curry(f2, f0) gives a Functor that accepts a single integer, v, and returns 3 + v.

f0 needn't be a constant, it could be any function that returns an appropriate result for f2's consumption.

Parameters:
f2 -
f0 -

indexWhere

public static <T> int indexWhere(Iterable<T> all,
                                 Filter<? super T> filter)
Find the 0-based index of the first value of a collection satisfying the filter.

Type Parameters:
T -
Parameters:
all -
filter -
Returns:
the 0-based index of the first value of a all satisfying filter or -1

lastIndexWhere

public static <T> int lastIndexWhere(Iterable<T> all,
                                     Filter<? super T> filter)
Find the 0-based index of the last value of a collection satisfying the filter.

Type Parameters:
T -
Parameters:
all -
filter -
Returns:
the 0-based index of the last value of a all satisfying filter or -1


Copyright © 2011. All Rights Reserved.