In scalaz, the function endoin is Function1Opsimplemented as follows:
def endo(implicit ev: R =:= T): Endo[T] =
Endo.endo(t => ev(self(t)))
I am curious why the body has a Endo.endofunction, and not just taking self ... like Endo.endo(self), which behaves the same way Endo.endo(t=> ev(self(t))).
Here is my facial expression, and I do not see the difference between them. Did I miss something?
def endo[R, T](f: R => T)(implicit ev: T =:= R) = (x: R)=> ev(f(x))
def endo2[R, T](f: R => T)(implicit ev: T =:= R) = f
Also, doesn't the first implementation add some overhead at runtime?
source
share