Richard Searle


Defaulting type with Scala implicits

13 Jul 2013

This stackoverflow answer shows how a default type can be specified, using some interesting side effects of the Scala implicit rules. Scala 2.10.1 allows the code to be further simplified
object DefaultsTo {
 implicit def default[B] = new DefaultsTo[B, B]
 implicit def overrideDefault[A,B] = new DefaultsTo[A,B]
The  T DefaultsTo Node looks rather strange but is actually the infix form of DefaultsTo[T,Node]