Is the ordered flow decreasing in order?

I have Listfrom A, B, C.

C reduce A reduce B != A reduce B reduce C (however, A reduction (B decreases C) is fine).

In other words, my reduction operation is associative, but not commutative.

Does java ensure an ordered sequential stream (e.g., by default from a list) that pruning will always be performed according to the order of the meeting? In other words, will Java abbreviations be reduced (such that B reduces A instead of A decreases B)?

(Hope this is clear enough).

to add a little demo and maybe help clarify

Stream.of(" cats ", " eat ", " bats ")
  .reduce("", (a, b) -> a + b); // cats eat bats

With the above, can bats ever appear or there are bats? Is it guaranteed somewhere in the spec?

+4
source share
4

( @shmosel ).

, .

. , .

, . :

, , , , .

, , :

(a + b) + c = (a + c) + b

, .

+4

Stream.of(), :

, .

, , , javadoc stream ops :

, . , ; , .

reduce, , , ( , java8 java9, , reduce, , ).

, , . , , map filter, , , , , - .

note: .

, ; , [1, 2, 3], (x → x * 2) [2, 4, 6]

( ):

.

, , , { a, b, c, d}, a + b , c + d , , (a + b) + (c + d), . , ( ), .

+1

.

  • java (, ), ?

, " ", , , .

  1. Stream.of(" cats ", " eat ", " bats ")
      .reduce("", (a, b) -> a + b); // cats eat bats
    
    , - " " " "? - ?

( ), " cats eat bats ", (. ). , , ,

, .reduce("", String::concat) , . , (a,b) -> b .

"" :

op , :

(a op b) op c == a op (b op c)

, :

a op b op c op d == (a op b) op (c op d)

, (a op b) (c op d), op .

, min max .

+1

For me, this is the ad unit in the abbreviation docs "This is equivalent ... but not limited to sequential execution."

The order of execution does not coincide with the order of the meeting. A stream pipeline is allowed to run "cats" + ("eat" + "bats")or("cats" + "eat") + "bats"

0
source

Source: https://habr.com/ru/post/1695426/


All Articles