codeconsole opened a new pull request, #3256:
URL: https://github.com/apache/groovy/pull/3256

   https://issues.apache.org/jira/browse/GROOVY-12722
   
   `sumParallel(Collection<T>, BinaryOperator<T>)` is a reduction with a 
required two-argument combiner, where `sum()` adds the elements and 
`sum(Closure)` adds their transforms. Code written by analogy with `sum` 
failed: `items.sumParallel { it.price }` called the one-parameter closure with 
two arguments, and under static compilation was rejected with "Wrong number of 
parameters for method target: apply(java.lang.Integer, java.lang.Integer)". 
That is the form a model with the parallel-collections documentation in front 
of it still wrote.
   
   Two additive forms in `ParallelCollectionExtensions`:
   
   - `sumParallel(Collection<?> self)` adds the elements with the left 
operand's `plus`, as `sum()` does; an empty collection gives `null`.
   - `<T, R> R sumParallel(Collection<T> self, Closure<R> closure)`, with 
`@ClosureParams(value = FromString, options = ["T", "T,T"])`: a one-parameter 
closure is a transform whose results are added; a two-parameter closure is the 
combiner of the `BinaryOperator` form, so existing calls keep working and, 
under static compilation, keep their result type (`int combined = 
numbers.sumParallel { int a, int b -> a + b }`). The `BinaryOperator` overload 
stays for method references and Java callers.
   
   `CombinerChecker` leaves a one-parameter closure passed to `sumParallel` 
alone: it is a transform, not a combiner. `core-parallel-collections.adoc` and 
the GPars migration table show the three forms.
   
   Tests: `ParallelCollectionTest.testSumParallelAddsUpLikeSum` (numbers, 
decimals, strings, lists, empty and one-element collections, the transform, the 
combiner, a method reference, and the three forms under `@CompileStatic`), 
`CombinerCheckerTest.transform_closure_is_not_a_combiner` (strict mode). Also 
run locally: `groovy.concurrent.ParallelCollectionTest`, `DesignPatternsTest`, 
`ParallelExecutorTasksTest` and `CombinerCheckerTest`, 134 tests, passing.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to