Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Sybex Practice Exam book - Chap 20 Q14

Ranch Hand
Posts: 50
3

A. (a,b) -> (a-b)
B. (a,b) -> 5
C. (a,b) -> i++
D. None of the above are appropriate.

The answer in the book is B, because it satisfies the two requirements - being associative and stateless. I totally agree with this answer if the reduce had just two arguments - identity and accumulator.
I am confused here , because there is a combiner also present in the reduce method which is s1+s2. Now, combiner has the contract that should return u, which is satisfied here as identity is 0. There is one more requirement : should be equivalent to
Suppose u and t both here are 5 as accumulator returns 5 for any two values in stream. so, combiner.apply(5, 5) is 10 whereas accumulator.apply(5,5) would return 5.  So, as a whole , to me the answer D looks closer.
Please clarify if my understanding is not right.

Greenhorn
Posts: 9
Hi
I'm also confused here
My explanation could be that in this case the combiner cannot be considered a function of two variables f(u, a(i,t)) because a(i,t) returns always a constant. Therefore we have more something like: f(x) = x+c, whereas c is a constant. And the compatibility requirement between function combiner and function accumulator is not more relevant because the second one is a constant.
Though, a little help in order to understand better the explanation would be appreciated.
Thanks

Zanna Bianca
Greenhorn
Posts: 9
I doubled checked this question can be found in Sybex OCA OCP Practice Test Chapter 19, not Chap 20, Q14.

Zanna Bianca
Greenhorn
Posts: 9
oh..in book is chap 20...sorry, my mistake..

author & internet detective
Marshal
Posts: 38152
617
• 1
That sounds reasonable. I'm going to check with Scott. Parallel streams make my head spin.

Note that there is a difference in chapter # between the internet and book for the later half. The web counts the OCA practice exam as a chapter # and the book does not. So it could have easily been both ch 19 and 20 .

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?