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.

CElliott (12) [Avatar] Offline
#1
Around location 1009 in the Kindle edition, the book says "The difference between Chain and Apply is that apply returns ordinary scala values, but the function in Chain returns an element, ... ."

But at location 1039 it says, "First you use Apply to package the argument elements into a single element whose value is a tuple of values of the arguments."

According to the documentation, the abstract base class Apply "(r)eturns a list of arguments on which the element depends".

So, what does Apply actually return, an Element, a scala value, or a list of scala values?
avi.pfeffer (102) [Avatar] Offline
#2
Hi,

Thank you for your question.

As a Scala constructor, Apply takes 1 to 5 Elements as arguments and returns an Element. For example,

Apply(Flip(0.3), Flip(0.4), (b1: Boolean, b2: Boolean) => b1 && !b2)

takes two Element[Boolean]s and a function (Boolean, Boolean) => Boolean and returns an Element[Boolean].

However, the best way to think about an element is as a random process. What the Element[Boolean] that is returned by this Apply represents is this:
The process of taking the *values* produced by the two argument elements, applying the given function to them, and returning the result.
So the process defined by the Apply can be understood as taking Scala values and returning a Scala value.
In contrast, the function in a Chain returns an element, and the corresponding process is more complex.

Does this help?

Thanks,

Avi