How can I “merge” these two methods into one:
def m[A, B](x: A, f: A => B): Widget[B] = new Widget(f(x)) def m[A](x: A): Widget[A] = m(x, identity[A])
I’d like to have a single method where
f is optional and, when it’s not provided, the method produces a
Widget[A]. I’m trying to bring the
A =:= B bound into play, but I can’t see how. (I can live with a Curried version of the method where
f is implicit, if necessary).
EDIT: This works in Curried form (identity is available implicitly):
def m[A, B](x: A)(implicit f: A => B): Widget[B] = new Widget(f(x))
How about the non-Curried form?