commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Horman" <>
Subject RE: [functor] predicates
Date Mon, 28 Apr 2003 18:31:17 GMT
Ok, I see. I would think though that using these predicates with lists would
be very common, and the currying technique is a little cumbersome. Maybe the
addition of a static function in each predicate that would return the right
bound version of the same would be useful.

inner class: new IsLessThan.RightBound(new Integer(7));
static method: IsLessThan.bindRight(new Integer(7));
unary and binary predicate (internally right bound): new IsLessThan(new

Just a thought. It just seems like one of the goals of functors is to reduce
code and side effects, thereby reducing errors. Saving the isLessThan
predicate and then using it in the select introduces a side effect. I would
prefer to do more of the work in line., new IsLessThan(7));, new

Actually, in the interest of reducing keystrokes something like this might

  // returns unary right bound version of IsLessThan
  Is.lessThan(new Integer(7));

  // returns binary version of IsLessThan

Where "Is" is a factory for "Is" predicates.


It would be nice to get rid of all of the "new" declarations in the usage of


-----Original Message-----
From: Rodney Waldhoff []
Sent: Monday, April 28, 2003 7:54 AM
To: Jakarta Commons Developers List
Subject: Re: [functor] predicates

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:, isLessThan7);

- Rod <>

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
>, etc. Or would it make more
> sense to renamed the existing binary predicates to BinaryIsLessThan and
> create a UnaryIsLessThan?
> -jason
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message