Internal and External truncation conditions
Remi Forax
forax at univ-mlv.fr
Sun Feb 10 05:46:08 PST 2013
On 02/10/2013 02:12 PM, Doug Lea wrote:
> On 02/09/13 18:24, Remi Forax wrote:
>> if forEachUntil takes a function that return a boolean, it's easy.
>>
>> try (BufferedReader r = Files.newBufferedReader(path,
>> Charset.defaultCharset())) {
>> return r.lines().parallel().forEachWhile(element -> {
>> if (regex.matcher(line).matches()) {
>> return false;
>> }
>> ...process the line
>> return true;
>> }
>> }
>>
>
> Which then becomes a variant of what I do in ConcurrentHashMap
> search{InParallel,Sequentially}, that applies to not only this
> but several other usage contexts:
>
> /**
> * Returns a non-null result from applying the given search
> * function on each (key, value), or null if none. Upon
> * success, further element processing is suppressed and the
> * results of any other parallel invocations of the search
> * function are ignored.
> *
> * @param searchFunction a function returning a non-null
> * result on success, else null
> * @return a non-null result from applying the given search
> * function on each (key, value), or null if none
> */
>
> You'd use this here with a function that processed if
> a match (returning null) else returning the first non-match.
> Or rework in any of a couple of ways to similar effect.
>
> This works well in CHM because of its nullness policy.
> Which allows only this single method to serve as the basis
> for all possible short-circuit/cancel applications.
> It is so handy when nulls cannot be actual elements
> that it might be worth supporting instead of forEachUntil?
> People using it would need to ensure non-null elements.
> Just a thought.
yes, findFirst and forEachWhile/forEachUntil are the same operation from
the implementation point of view if you have a value (not necessarily
null) that says NO_VALUE.
Now, I think it's an implementation detail and that from the user point
of view we should provide them both.
>
> -Doug
>
>
Rémi
More information about the lambda-libs-spec-observers
mailing list