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.

Mark Elston (133) [Avatar] Offline
#1
On page 137 there is the following line at the bottom of the page:

def taxIt: TaxStrategy => String => Double = s => p => s.taxIt(p)

I may have missed this elsewhere in the book but I don't understand what this line means or how to read it. Is it explained somewhere else in the book?

It appears to say that 'taxIt' is a function that returns a (function that takes a TaxStrategy and returns a function [that takes a String and returns a Double]). Is that correct?

The part after the '=' though, is even more confusing. What is going on there?

Mark
Mark Elston (133) [Avatar] Offline
#2
Re: Syntax question section 5.2.2
I think I understand it now. I'm hoping someone will confirm this for me, though.

I tried the following (a variation of th example on page 8 of the book):

  val inc: Int => Int = x => x+1


So this defines inc as a function that takes an Int and returns an Int and gives its value to be the function that takes 'x' (an Int) and returns 'x+1'. Calling it like this:

  inc(1)


returns 2.

OK. So the code on page 137 is similar. 'taxIt' is a function that takes a TaxStrategy and returns a function that takes a String and returns a Double. Specifically it returns the 'taxIt' member function from the provided TaxStrategy object passed in. Also, the 's' is the provided instance of the TaxStrategy class, 'p' is the String that the returned function will take.

The syntax is confusing to me. But I guess it makes sense if you stare at it long enough.

Mark