Review request for initial lambda functions and utils

Peter Levart peter.levart at marand.si
Tue Aug 9 02:03:49 PDT 2011


On 08/09/11, Mike Duigou wrote:
> - surprising behaviour
>     - self-inconsistency or surprising behaviour with respect to other Java APIs.

The following method in Blocks.java (and consequently the defender in Block.java):

    /**
     * Returns a Block which repeatedly performs the {@code apply} method of
     * this Block. The repetitions are terminated when the provided predicate
     * returns {@code false}. The predicate is tested after each iteration.
     *
     * @param block Block to {@code apply} repeatedly.
     * @param decider a predicate which determines whether to continue
     * calling the {@code apply} method.
     * @return a Block which repeatedly performs the {@code apply} method of
     * this Block.
     */
    public static <T> Block<T> repeatUntil(Block<T> block, Predicate<? super T> decider) {
        Objects.requireNonNull(block);
        Objects.requireNonNull(decider);

        return #{T t -> do{ block.apply(t); } while(decider.eval(t)); };
    }

...should eiher be named differently or do the expected thing (repeat UNTIL condition is TRUE - not WHILE condition is TRUE).

The expected behaviour is established in many languages for decades (Java unfortunately has no such language construct).

Maybe, instead of the current two methods:

Blocks.repeatWhile(Block, Predicate)
Blocks.repeatUntil(Block, Predicate)

Create the following three (to be consistent with Java language):

Blocks.whileDo(Block, Predicate)
Blocks.doWhile(Block, Predicate)
Blocks.doUntil(Block, Predicate)

Or alternatively (to emphasize repetition):

Blocks.whileRepeat(Block, Predicate)
Blocks.repeatWhile(Block, Predicate)
Blocks.repeatUntil(Block, Predicate)

Regards, Peter



More information about the lambda-dev mailing list