commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Horman" <ja...@jhorman.org>
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));
or
static method: IsLessThan.bindRight(new Integer(7));
or
unary and binary predicate (internally right bound): new IsLessThan(new
Integer(7));

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.

  CollectionAlgorithms.select(myCollection.iterator(), new IsLessThan(7));
  CollectionAlgorithms.select(myCollection.iterator(), new
IsLessThan.RightBound(7));
  CollectionAlgorithms.select(myCollection.iterator(),
IsLessThan.rightBind(7));

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

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

  // returns binary version of IsLessThan
  Is.lessThan();

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

Is.lessThan
Is.greaterThan
Is.equal
Is.nul
Is...

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

-jason

-----Original Message-----
From: Rodney Waldhoff [mailto:rwaldhoff@apache.org]
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:

  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





---------------------------------------------------------------------
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