|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectinfo.javelot.functionalj.Functions
The Functions class contains static methods that use functions to
perform various computations, which makes it possible to use certain functional
programming patterns. These patterns include:
Note about Folding
Folding consists of using a function that requires two parameters, and applying it to a collection of elements, each time using the result of the previous function call as the first parameter to the next function call. The result of the last function call is the overall result of the fold.
Folding can be performed from the left or from the right.
Folding a collection from the left using a function f, a
starting parameter p, and a collection of elements
[e1, e2, ..., en] is equal to:
f(f(f(f(p, e1), e2), ...), en)
Folding a collection from the right using a function f, a
starting parameter p, and a collection of elements
[e1, e2, ..., en] is equal to:
f(e1, f(e2, f(..., f(en, p))))
Note about Scanning
Scanning is similar to folding except that scanning returns a list of successive reduced values, from the left or from the right.
Thus, folding from the left takes the last element of the list that results from scanning from the left; folding from the right takes the first element of the list that results from scanning from the right.
Thanks to Paul Field for his suggestions on improving performance.
| Method Summary | |
static boolean |
all(Function1 p_function1,
Collection p_coll)
Determines if all of the elements of the collection satisfy the condition represented by the given function. |
static boolean |
all(Function1 p_function1,
Object[] p_array)
Version of all(Function1,Collection) that accepts an array. |
static boolean |
and(boolean[] p_array)
Version of and(Collection) that accepts an array. |
static boolean |
and(Boolean[] p_array)
Version of and(Collection) that accepts an array. |
static boolean |
and(Collection p_coll)
Returns the result of &&ing the Boolean
values in the given collection. |
static boolean |
any(Function1 p_function1,
Collection p_coll)
Determines whether any of the elements of the collection satisfy the condition represented by the given function. |
static boolean |
any(Function1 p_function1,
Object[] p_array)
Version of any(Function1,Collection) that accepts an array. |
static List |
filter(Function1 p_filter,
Collection p_coll)
Filters a collection of items according to a filter function, which accepts one parameter of the same type as the items, and returns a Boolean value indicating whether or not the item satisfies the
filter condition. |
static List |
filter(Function1 p_filter,
Object[] p_array)
Version of filter(Function1, Collection) which accepts an array. |
static List |
filterNot(Function1 p_filter,
Collection p_coll)
Same as filter(Function1,Collection), except that the elements that
do not satisfy the filter condition are returned. |
static List |
filterNot(Function1 p_filter,
Object[] p_array)
Version of filterNot(Function1, Collection) which accepts an array. |
static Object |
foldl(Function2 p_function2,
Object p_start,
Collection p_coll)
Folds a collection from the left using the given function and starting parameter. |
static Object |
foldl(Function2 p_function2,
Object p_start,
Object[] p_array)
Version of foldl(Function2,Object,Collection) that accepts an array. |
static Object |
foldl1(Function2 p_function2,
Collection p_coll)
Folds a collection from the left using the given function. |
static Object |
foldl1(Function2 p_function2,
Object[] p_array)
Version of foldl1(Function2,Collection) that accepts an array. |
static Object |
foldr(Function2 p_function2,
Object p_start,
Collection p_coll)
Folds a collection from the right using the given function and starting parameter. |
static Object |
foldr(Function2 p_function2,
Object p_start,
Object[] p_array)
Version of foldr(Function2,Object,Collection) that accepts an array. |
static Object |
foldr1(Function2 p_function2,
Collection p_coll)
Folds a collection from the right using the given function. |
static Object |
foldr1(Function2 p_function2,
Object[] p_array)
Version of foldr1(Function2,Collection) that accepts an array. |
static List |
map(Function1 p_function1,
Collection p_coll)
Maps a function to a collection of parameters, by calling the function with each element of the collection in turn as a parameter, and returning a list of the results. |
static List |
map(Function1 p_function1,
Object[] p_array)
Version of map(Function1, Collection) which accepts an array. |
static boolean |
or(boolean[] p_array)
Version of or(Collection) that accepts an array. |
static boolean |
or(Boolean[] p_array)
Version of or(Collection) that accepts an array. |
static boolean |
or(Collection p_coll)
Returns the result of ||ing the Boolean values
in the given collection. |
static List |
scanl(Function2 p_function2,
Object p_start,
Collection p_coll)
Scans a collection to return successive reduced values from the left. |
static List |
scanl(Function2 p_function2,
Object p_start,
Object[] p_array)
Version of scanl(Function2,Object,Collection) which accepts an array. |
static List |
scanl1(Function2 p_function2,
Collection p_coll)
Scans a collection to return successive reduced values from the left, using the first element of the collection as a starting parameter. |
static List |
scanl1(Function2 p_function2,
Object[] p_array)
Version of scanl1(Function2,Collection) that accepts an array. |
static List |
scanr(Function2 p_function2,
Object p_start,
Collection p_coll)
Scans a collection to return successive reduced values from the right. |
static List |
scanr(Function2 p_function2,
Object p_start,
Object[] p_array)
Version of scanr(Function2,Object,Collection) that accepts an array. |
static List |
scanr1(Function2 p_function2,
Collection p_coll)
Scans a collection to return successive reduced values from the right, using the* first element of the collection as a starting parameter. |
static List |
scanr1(Function2 p_function2,
Object[] p_array)
Version of scanr1(Function2,Collection) that accepts an array. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static List map(Function1 p_function1,
Collection p_coll)
throws FunctionException
p_function1 - the function to map.p_coll - the collection of parameters on which to map the function.
null or empty, an empty
list is returned.
FunctionException - thrown if the function is null, or
if one is thrown while using the function.
public static List map(Function1 p_function1,
Object[] p_array)
map(Function1, Collection) which accepts an array.
map(Function1, Collection).
public static List filter(Function1 p_filter,
Collection p_coll)
throws FunctionException
Boolean value indicating whether or not the item satisfies the
filter condition.
p_filter - the filter function.p_coll - the collection of items to be filtered.
true.
FunctionException - thrown if an exception occurs while calling the
filter function.
public static List filter(Function1 p_filter,
Object[] p_array)
throws FunctionException
filter(Function1, Collection) which accepts an array.
FunctionExceptionfilter(Function1, Collection).
public static List filterNot(Function1 p_filter,
Collection p_coll)
throws FunctionException
filter(Function1,Collection), except that the elements that
do not satisfy the filter condition are returned.
FunctionExceptionfilter(Function1,Collection)
public static List filterNot(Function1 p_filter,
Object[] p_array)
throws FunctionException
filterNot(Function1, Collection) which accepts an array.
FunctionExceptionfilterNot(Function1, Collection).
public static Object foldl(Function2 p_function2,
Object p_start,
Collection p_coll)
throws FunctionException
p_function2 - the function to use while folding.p_start - the starting parameter to the function.p_coll - the collection of elements to be folded.
FunctionException - thrown if the function is null, or
if an exception occurs while using the function.
public static Object foldl(Function2 p_function2,
Object p_start,
Object[] p_array)
throws FunctionException
foldl(Function2,Object,Collection) that accepts an array.
FunctionExceptionfoldl(Function2,Object,Collection)
public static Object foldl1(Function2 p_function2,
Collection p_coll)
throws FunctionException
p_function2 - the function to use while folding.p_coll - the collection of elements to be folded.
FunctionException - thrown if the collection is null or
empty.foldl(Function2, Object, Collection)
public static Object foldl1(Function2 p_function2,
Object[] p_array)
throws FunctionException
foldl1(Function2,Collection) that accepts an array.
FunctionExceptionfoldl1(Function2,Collection)
public static List scanl(Function2 p_function2,
Object p_start,
Collection p_coll)
throws FunctionException
p_function2 - the function used for scanning.p_start - the starting parameter to the function.p_coll - the collection of elements to be scanned.
FunctionException - thrown if the function is null or if
an exception occurs while calling the function.
public static List scanl(Function2 p_function2,
Object p_start,
Object[] p_array)
throws FunctionException
scanl(Function2,Object,Collection) which accepts an array.
FunctionExceptionscanl(Function2,Object,Collection)
public static List scanl1(Function2 p_function2,
Collection p_coll)
throws FunctionException
FunctionExceptionscanl(Function2, Object, Collection).
public static List scanl1(Function2 p_function2,
Object[] p_array)
throws FunctionException
scanl1(Function2,Collection) that accepts an array.
FunctionExceptionscanl1(Function2,Collection)
public static Object foldr(Function2 p_function2,
Object p_start,
Collection p_coll)
throws FunctionException
p_function2 - the function to use while folding.p_start - the starting parameter to the function.p_coll - the collection of elements to be folded.
FunctionException - thrown if the function is null, or
if an exception occurs while using the function.
public static Object foldr(Function2 p_function2,
Object p_start,
Object[] p_array)
throws FunctionException
foldr(Function2,Object,Collection) that accepts an array.
FunctionExceptionfoldr(Function2,Object,Collection).
public static Object foldr1(Function2 p_function2,
Collection p_coll)
throws FunctionException
p_function2 - the function to use while folding.p_coll - the collection of elements to be folded.
FunctionException - thrown if the list is null or empty.foldr(Function2,Object,Collection)
public static Object foldr1(Function2 p_function2,
Object[] p_array)
throws FunctionException
foldr1(Function2,Collection) that accepts an array.
FunctionExceptionfoldr1(Function2,Collection).
public static List scanr(Function2 p_function2,
Object p_start,
Collection p_coll)
throws FunctionException
p_function2 - the function used for scanning.p_start - the starting parameter to the function.p_coll - the collection of elements to be scanned.
FunctionException - thrown if the function is null.
public static List scanr(Function2 p_function2,
Object p_start,
Object[] p_array)
throws FunctionException
scanr(Function2,Object,Collection) that accepts an array.
FunctionExceptionscanr(Function2,Object,Collection).
public static List scanr1(Function2 p_function2,
Collection p_coll)
throws FunctionException
FunctionExceptionscanr(Function2,Object,Collection).
public static List scanr1(Function2 p_function2,
Object[] p_array)
throws FunctionException
scanr1(Function2,Collection) that accepts an array.
FunctionExceptionscanr1(Function2,Collection).
public static boolean and(Collection p_coll)
throws FunctionException
&&ing the Boolean
values in the given collection. Thus if at least one value is
false, the result will be false.
p_coll - the collection of Boolean values to be
&&ed.
true if all the values of the collection are
true; false otherwise.
FunctionException - thrown if not all elements of the collection are
of Boolean type.
public static boolean and(Boolean[] p_array)
throws FunctionException
and(Collection) that accepts an array.
FunctionExceptionand(Collection).
public static boolean and(boolean[] p_array)
throws FunctionException
and(Collection) that accepts an array.
FunctionExceptionand(Collection).
public static boolean all(Function1 p_function1,
Collection p_coll)
throws FunctionException
p_function1 - the function that represents the condition to be met.p_coll - the collection of elements to be tested against the condition.
true if all of the elements of the collection satisfy the
condition; false otherwise.
FunctionException
public static boolean all(Function1 p_function1,
Object[] p_array)
throws FunctionException
all(Function1,Collection) that accepts an array.
FunctionExceptionall(Function1,Collection).
public static boolean or(Collection p_coll)
throws FunctionException
||ing the Boolean values
in the given collection. Thus if at least one value is true, the
result will be true.
p_coll - the collection of Boolean values to be
||ed.
false if all the values of the collection are
false; true otherwise.
FunctionException
public static boolean or(Boolean[] p_array)
throws FunctionException
or(Collection) that accepts an array.
FunctionExceptionor(Collection).
public static boolean or(boolean[] p_array)
throws FunctionException
or(Collection) that accepts an array.
FunctionExceptionor(Collection).
public static boolean any(Function1 p_function1,
Collection p_coll)
throws FunctionException
p_function1 - the function that represents the condition to be met.p_coll - the collection of elements to be tested against the condition.
true if at least one element of the collection satisfies
the condition; false otherwise.
FunctionException
public static boolean any(Function1 p_function1,
Object[] p_array)
throws FunctionException
any(Function1,Collection) that accepts an array.
FunctionExceptionany(Function1,Collection).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||