commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodney Waldhoff <rwaldh...@apache.org>
Subject Re: [functor] predicates
Date Mon, 28 Apr 2003 14:54:07 GMT
You can use a process known as Currying to convert a binary function to a
unary one.  There are types in functor.adapater for binding a constant
value to the left-side or right-side argument of BinaryFunction,
BinaryPredicate or BinaryProcedure, yielding a UnaryFunction,
UnaryPredicate or UnaryProcedure, respectively.

For example,

 UnaryPredicate isLessThan7 = new RightBoundPredicate(
     new IsLessThan(),
     new Integer (7));


Hence, to select all the elements of myCollection less than 7, use:

  CollectionAlgorithms.select(myCollection.iterator(), isLessThan7);


- Rod <http://radio.weblogs.com/0122027/>

On Mon, 28 Apr 2003, Jason Horman wrote:

> Many of the comparator predicates are BinaryPredicates. Should then not be
> both binary and unary. For example, the IsLessThan predicate is strictly
> binary, rendering it useless for
> CollectionAlgorithms.select/reject/contains, etc. Or would it make more
> sense to renamed the existing binary predicates to BinaryIsLessThan and
> create a UnaryIsLessThan?
>
> -jason
>  jason@jhorman.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message