Scala Option map

If you followed along, you might remembermapfrom theList. In Scala, and in functional programming, you are going to hear aboutmapa whole bunch.

mapcomes 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 themapmethod.

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

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 themapwasn't too bad, was it? And you used it before with theList.

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

  • What happen wheninputis set toNone?
  • What happen if you replacegetOrElsebyget? withSomeand withNone.
  • You might have written something like.map(a => a + 1)in your solution, try replacinga => aby_. This is some teasing for some upcoming SKB.

Reveal more information and clues
Load Exercise