Coproduct also supports mapping given a polymorphic function such as
Coproduct also supports mapping given a polymorphic function such as
object sizeM extends Poly1 { implicit def caseInt = at[Int](i => (i, i)) implicit def caseString = at[String](s => (s, s.length)) implicit def caseBoolean = at[Boolean](b => (b, 1)) }
type ISB = Int :+: String :+: Boolean :+: CNil val isb = Coproduct[ISB]("foo")
In the same way that adding labels To the elements of an HList gives us a record, adding labels to the elements of a Coproduct gives us a discriminated union.
The parameterless execute method has been deprecated and will be removed in a future version of ScalaTest. Please invoke execute with empty parens instead: execute().
The trap method is no longer needed for demos in the REPL, which now abreviates stack traces, and will be removed in a future version of ScalaTest
Coproducts and discriminated unions
shapeless has a Coproduct type, a generalization of Scala's
Either
to an arbitrary number of choices. Currently it exists primarily to supportGeneric
(see the next section), but will be expanded analogously toHList
in later releases. CurrentlyCoproduct
supports mapping, selection and unification