When you're starting to use functional programming libraries in scala there is something which might not feel right to you. But you suppress that feeling because everything seems to work just a fine. You try to move on, but a question is racing through your head. I'm talking of course about:
Why the hell can I call
flatMap
andmap
on my data types, even though it isn't implemented on my data types?
Consider a small example. We will write our own mirror of the Option
data type. The original Option
has two cases, Some(a)
if there is a value and None
if there is none. Let's call our data type Maybe
which the cases Just(a)
and Empty
.
sealed trait Maybe[+A]