Scala Option map

If you followed along, you might remember map from the List. In Scala, and in functional programming, you are going to hear about map a whole bunch.

map comes from the functional programming world, and from category theory in mathematics. We are going to dive deeper into those two concepts in the future but for now let's focus only on the map method.

Just to throw it out there, but don't get hang on it too much, map is part of what is called a functor.

Can you feel that the “m” word is going to show up soon ? Should we pop the bubble now ?

Let's rip off the bandage, right now. MONAD !

That's it, we said it. There is no turning back now. Good luck !

Have you recovered from the m-encounter ? Using the map wasn't too bad, was it? And you used it before with the List.

There are few things to try to modify in this exercise. Go ahead and try those:

  • What happen when input is set to None?
  • What happen if you replace getOrElse by get ? with Some and with None.
  • You might have written something like .map(a => a + 1) in your solution, try replacing a => a by _. This is some teasing for some upcoming SKB.

Reveal more information and clues
Load Exercise