I'm having difficulty figuring out how to make the jump from a Scala high-order function definition to the example provided. It was provided in this slide show on slide 81.
Here's the high-order function definition:
trait X[A] { def map[B](f: A => B): X[B] }
Here's the examples provided:
(1 to 10) map { x => x * 2 } // evaluates to Vector(2, 4, ..., 20)
(1 to 10) map { _ * 2 } // shorthand!
Huh?! There just HAS to be some steps in here I am missing. I get that the examples may be leveraging both the function definition AND some Scala niceties. I just don't have enough experience reading Scala and making the connecting assumptions yet.
My background is as a Java OO. I am now learning Scala and functional programming. And this is not the first example like this I have not understood. It's just the first one where I felt I had the courage to post knowing I would look ignorant.
I did try to research this. First, I went to the Scala "bible", "Programming in Scala 2nd Edition", and attempted to make sense of if from there (pages 165-9). Then, I did a search here on StackOverflow. And I found several links that talk around the area. But, nothing actually shows me, STEP-BY-STEP, the connection between a Scala high-order function definition and the provided examples in a way that maps to the particular instance in this slide.
Here's what I found on StackOverflow:
- Scala: Workshop Advice
- More on generic Scala functions
- Scala: How to define "generic" function parameters?
I'm just now realizing that I skipped Google and came straight to StackOverflow. Hmmm. If you google and find just the right link, I would love seeing it. I've run out of time to sift through all the Google links which use terms like monkey-monad, blastomorphisms, etc. while leaving me even more confused and less likely to try and figure this out.