For the following map
signature, am I reading it correctly?
object OptionImpl extends Option {
def map[B](f: A => B): Option[B]
}
source - FP in Scala
[B]
means only objects of type B
can call this function
f: A => B
means that it accepts 1 argument, a function, that returns the same type B
I'm fuzzy on a concrete example of this function.
B
is just a wildcard (i.e. generic). It just says that these two types are the same:That is, it says: if you pass me a function that converts
A
s toB
s, I will give you back anOption
that may contain aB
(whereB
can be any type).