case class Foo(i: Int, s: String, b: Boolean) val fooGen = Generic[Foo] val foo = Foo(23, "foo", true)
We can convert back and forth case class to their HList Generic representation
A natural extension of Generic's mapping of the content of data types onto a sum of products representation is to a mapping of the data type including its constructor and field names onto a labelled sum of products representation, ie.
A natural extension of Generic's mapping of the content of data types onto a sum of products representation is to a mapping of the data type including its constructor and field names onto a labelled sum of products representation, ie. a representation in terms of the discriminated unions and records that we saw above. This is provided by LabelledGeneric. Currently it provides the underpinnings for the use of shapeless lenses with symbolic path selectors (see next section) and it is expected that it will support many scenarios which would otherwise require the support of hard to maintain special case macros.
case class Book(author: String, title: String, id: Int, price: Double)
Typically values of Generic for a given case class are materialized using an implicit macro, allowing a wide variety of structural programming problems to be solved with no or minimal boilerplate.
Typically values of Generic for a given case class are materialized using an implicit macro, allowing a wide variety of structural programming problems to be solved with no or minimal boilerplate. In particular the existing lens, Scrap Your Boilerplate and generic zipper implementations are now available for any case class family (recursive families included, as illustrated below) without any additional boilerplate being required
import poly._ // Simple recursive case class family sealed trait Tree[T] case class Leaf[T](t: T) extends Tree[T] case class Node[T](left: Tree[T], right: Tree[T]) extends Tree[T] // Polymorphic function which adds 1 to any Int and is the identity // on all other values object inc extends ->((i: Int) => i+1)
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
Please use 'an [Exception] should be thrownBy { ... }' syntax instead
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.
Generic representation of (sealed families of) case classes
The
Iso
s of earlier shapeless releases have been completely reworked as the newGeneric
type, which closely resembles the generic programming capabilities introduced to GHC 7.2.Generic[T]
, whereT
is a case class or an abstract type at the root of a case class hierarchy, maps between values ofT
and a generic sum of products representation (HList
s andCoproduct
s),