Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created August 29, 2015 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/88acf7008486e27ea62c to your computer and use it in GitHub Desktop.
Save xuwei-k/88acf7008486e27ea62c to your computer and use it in GitHub Desktop.
package multimplicit
sealed abstract class Multimplicit extends Product with Serializable
final case class ::[+H, +T <: Multimplicit](head : H, tail : T) extends Multimplicit {
override def toString = head match {
case _: ::[_, _] => "("+head+") :: "+tail.toString
case _ => head+" :: "+tail.toString
}
}
object :: {
implicit def instance[H, T <: Multimplicit](implicit h: H, t: T): H :: T =
::(h, t)
}
sealed abstract class MNil extends Multimplicit {
override def toString = "HNil"
def ::[H](h : H) = multimplicit.::(h, this)
}
case object MNil extends MNil {
implicit val self: this.type = this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment