We know that any generic type F[_]
withmap
method, which complies to some laws, is a functor. For instance, List[_]
, Option
Well, once you know something is a Functor, you don't just get map
, you get all of the functions you can derive with it too
For example, it's possible to derive the function lift
in a way that works for any functor.
Lift will "lift" a function from A => B
to F[A] => F[B]
for some Functor F[_]
and is defined as
def lift[A, B](f: A => B): F[A] => F[B] = map(_)(f)
If you are using a library like cats or scalaz then you get these functions for free. The cats documentation has a few other examples you might be interested in