The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

undjask (13) [Avatar] Offline
According to your request posting about things confusing the reader (myself in that case) here are the things that confused me so far. If something is not understandable, I'll try reformulating it. English is not my native language.

Meap V02

Confusing things

Page 54
- Where does Block come from? Did you mean the Consumer-Interface?

Page 61
- Apple apple1 = fruitFactory.get(). The Function-Interface has no method get()
or did I miss something?

Page 84 / 4.3.2 Flattening Streams
- I found the desciption of flatMap to be confusing. I think the JDK
documentation is a bit more precise/understandable. May be you could
use some examples/wording from there?

Page 96 / 4.6.1
- I stumbled upon the distinct() in query 3. After realizing it works because
there are four distinct traders pointing to four different references, I thought
it would be nice if you could provide an equals/hashCode() combo.

General stuff

Page 99
- Query 7 could be "more challenging". Personally I find it more interesting
returning the Transaction containing the highestValue instead of the value.

Page 103
- Is there an elegant method for optimizing the generation of pythagorean
triples while sticking to stream-operations and lambdas? Sqrt is quite costly
and calculated twice.
raoul-gabriel.urma (37) [Avatar] Offline
Re: confusing things

First of all let me say that we are very grateful for you feedback! This is exactly what helps us improve the content: things that are confusing & suggestion for improvements.

Page 54:
It should be Consumer<T>. It was called Block<T> in previous jdk8 version.

Page 61:
It should be apply. We should even be using BiFunction because the Apple constructor has two arguments weight and color:

BiFunction<Integer, String, Apple> fruitFactory = Apple::new;
Apple red150 = fruitFactory.apply(150, "red");

Page 84:
I'll revisit this part for the next iteration of chapters 1-5. (probably available in 3weeks).

Page 96:
You are right, i'll modify this query to include a sneaky extra duplicate Trader.

Page 99:
It's true query 7 could be better. I will add another query 8 to find the "smallestTransaction". It will also provide a hook to mention BinaryOperator.minBy/maxBy: [apologies for formatting, seems like this forum system doesn't support code indentation]

Optional<Transaction> smallestTransaction =

Page 103:
I'll give it a think. An alternative could be to pass down a tuple that contains the sqrt already:
Stream<double[]> pythagoreanTriples2 =
IntStream.rangeClosed(1, 100).boxed()
.flatMap(a ->
IntStream.rangeClosed(a, 100).boxed()
.map(b -> new double[]{a, b, Math.sqrt(a*a + b*b)})
.filter(t -> t[2] % 1 == 0) // could be a named predicate
undjask (13) [Avatar] Offline
Re: confusing things
I'm currently reading Chapter 5 and realized that my statement about Page 99 might be obsolete. In chapter 5 you are elaborating further on the min/max topic using the ternary op and explaining the BinaryOperator maxBy. So changing the example might be redundant. smilie