7 Ağustos 2019 Çarşamba

Stream.forEach metodu

Giriş
Açıklaması şöyle.
The behavior of this operation is explicitly nondeterministic
forEach metodu aynı zamanda Iterable arayüzüne de eklendi. Böylece stream ve Iterable benzer işlevleri yerine getirebiliyor.

Neden forEach
Functional style forEach() kullanmanın bazı avantajları şöyle. Ancak ben bun listeye tam anlamıyla katılamıyorum. Imperative döngü kurmak daha kolay gibi geliyor.
- The for loops are inherently sequential and are quite difficult to parallelize.
- Such loops are non-polymorphic; we get exactly what we ask for. We passed the collection to for instead of invoking a method (a polymorphic operation) on the collection to perform the task.
- At the design level, the code fails the "Tell, don't ask" principle. We ask for a specific iteration to be performed instead of leaving the details of the iteration to underlying libraries.

Hiç yorum yok:

Yorum Gönder