The package documentation java.util.streamgives this definition for identification in the context of the abbreviation:
java.util.stream
The value identitymust be an identity for the combiner function. This means that for everyone u, itβs combiner.apply(identity, u)equal u.
identity
u
combiner.apply(identity, u)
Stream.reduce(), and its primitive copies offer a similar definition.
Stream.reduce()
As I understand it, this definition is necessary to support parallel threads. For example, a non-zero initial value for decreasing the sum can be multiplied by the number of parallel processors, which unpredictably distorts the final result.
But this definition seems stricter than necessary to support parallelism. Why not require an idempotent value x, which combiner.apply(x, x)is equal x? This will protect functions, such as Integer::sum, (a, b) -> a * band String::concatfrom skewing over several processes, while allowing you to use any seed with idempotent functions, such as Math::max, (a, b) -> a | band Sets::intersection.
x
combiner.apply(x, x)
Integer::sum
(a, b) -> a * b
String::concat
Math::max
(a, b) -> a | b
Sets::intersection
Is there any unique advantage to the identity value that I am missing?
" ?". , . , .
2- . 2 (a, b). i, - op.
(i op a) op b. (i op a) op (i op b) ( , ). , op b
, , , . , i, , op = i, , (i op a) op (i op b) b op a b.
-, , - : (x, y) -> (x + y).replaceAll(" +", " "). " " , . .
(x, y) -> (x + y).replaceAll(" +", " ")
" "
combiner.apply(x, x) == x ?
combiner.apply(x, x) == x
, max(). , max(x, x) == x . x, , identity max().
max()
max(x, x) == x
, , , max() MIN_VALUE ( " ", null NaN, ).
MIN_VALUE
null
NaN
Source: https://habr.com/ru/post/1687340/More articles:utf16 vs utf-16 - pythonWhy does this dotnet test test only work in a Docker container? - dockerbook application crashes on the screen saver (solid loading wheel) - ion - iosBinary Search Comparison - javaProcessing "Type of exception thrown is not a construction other than the old one." Warning - c ++arangodb AQL How to change the value of an object in a nested array? - arangodbComputing projection matrices in J - matrixhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1687343/trying-to-prevent-duplicate-values-to-be-added-to-an-array&usg=ALkJrhht1eYhmmQ9kyDRF8zgt3uD7YL76wjava 8 handling custom exceptions when using Collectors.toMap - java.net Core - HTTPS with AWS load balancer and elastic bean stack not working - httpsAll Articles