-
Notifications
You must be signed in to change notification settings - Fork 533
Release notes: shapeless 2.1.0
This is the final release of shapeless-2.1.0. A detailed feature overview is in preparation, but in the meantime these release notes provide a summary of changes since shapeless 2.0.0, and a guide to migration from shapeless 2.0.0 is available on the shapeless wiki.
Since shapeless 2.1.0-RC1 was published, one issue was found and has been
fixed relating to an interaction between the macro supporting shapeless's
Lazy
and the Scala presentation compiler. This did not affect code
generation, but it did result in spurious errors being reported by the Scala
IDE for Eclipse.
A big "Thank You!" to everyone who has contributed to this release, either directly in code or by using and discussing it, by inviting me to talk about it, and especially by ignoring my advice that shapeless was experimental and should under no circumstances be used in production. In particular I would like to thank Alexandre Archambault (@alxarchambault), Edward Pierzchalski (@eapi_), Michael Pilquist (@mpilquist), Sam Halliday (@fommil) and Stacy Curl (@stacycurl) for their commitment to and assistance with the massive improvements in automatic type class derivation which are the primary new feature of this release.
Contributors for shapeless 2.1.0 are,
- Alexandre Archambault (@alxarchambault)
- Andrew Brett (@Ephemerix)
- Chris Hodapp (@clhodapp)
- Cody Allen (@fourierstrick)
- Dale Wijnand (@dwijnand)
- Eugene Burmako (@xeno_by)
- Filipe Nepomuceno [email protected]
- Howard Branch (@purestgreen)
- Jean-Remi Desjardins (@jrdesjardins)
- Jules Gosnell [email protected]
- Kevin Wright (@thecoda)
- Lars Hupel (@larsr_h)
- Mario Pastorelli (@mapastr)
- Michael Pilquist (@mpilquist)
- Oleg Aleshko (@OlegYch)
- Owein Reese (@OweinReese)
- Pascal Voitot (@mandubian)
- Renato Cavalcanti (@renatocaval)
- Sam Halliday (@fommil)
- Sarah Gerweck (@SGerweck)
- Simon Hafner (@reactormonk)
- Stacy Curl (@stacycurl)
- Travis Brown (@travisbrown)
Many thanks to all of you and everyone else who has contributed ideas, enthusiasm and encouragement.
There are a large number of new features, refactorings and bugfixes in shapeless 2.1.0. The most significant of these are,
-
Improvements in Generic
- Generalized to support all types which are sufficiently case-class like. In particular this allows non-case classes with lazy val members to be operated on generically in the same way as vanilla case classes. This significantly expands the range of types for which type classes and lenses can be derived automatically. It also supports a library-level implementation of "case classes a la carte".
- The implicit macro which materializes instances of Generic now uses [fundep materailization][fundep], a new feature of macros in Scala 2.11.x. This eliminates some issues with type inference which could be experienced when working with Generic in Scala 2.10.x. This functionality is available in Scala 2.10.4 via the Macro Paradise compiler plugin, and will be available in Scala 2.10.5 without the plugin, using a new -Yfundep-materialization compiler flag.
- Dedicated macro support for LabelledGeneric has been replaced by a non-macro implementation in terms of Generic and a separate type class which provides a labelling. Amongst other things, this facilitates the provision of alternative labellings.
- Added type classes witnessing that a type has a product or coproduct generic representation type (HasProductGeneric, HasCoproductGeneric).
-
Significantly enhanced type class derivation,
- The
Lazy
type is now able to materialize instances of its type arguments in a much more general way, allowing (mutually) recursive values to be constructed implicitly. - Combined with the enhanced
Generic
implementation, it has been possible to reimplement theTypeClass
family entirely in terms ofLazy
,Generic
,DefaultSymbolicLabelling
and standard Scala implicit resolution. This allows a much wider range of type classes to be derived for a much wider range of ADTs and ADT-like types. - The Scrap Your Boilerplate implementation has been completely reworked
in terms of
Lazy
andGeneric
and the specialized macro support has been removed.
- The
-
Many new HList/record/Coproduct/union/tuples/product operations have been added for these types as enumerated here.
-
An
Ordering
type class instance has been added forHList
s and aPartialOrdering
instance forCoproduct
s. -
Additional operations defined directly for all Scala Product types,
- Conversions to shapeless records, HLists and to tuples (toRecord, toHList, toTuple).
- Conversions to Maps, Traversables and to shapeless Sized types (toMap, toTraversable, toSized.
- Added the IsTuple type class witness that that a type is one of the family of Scala tuple types.
- Added an updateWith operation for tuples.
-
Record/union improvements
- As with HLists and Coproducts, records and* unions are now much more consistent and support many more common operations.
- Added a simulation of first class record/union types.
- Added toMap and mapValues operations.
- Added getField operation
- Added selectDynamic-based method-like element selection.
-
Optics (lenses and prisms) have been enhanced.
- The improvements to
Generic
mean that optics can now be automatically derived for a wider range of ADT-like types. - Optics can now be used as extractors in pattern match context.
- Scala's
selectDynamic
has been exploited to allow optic construction with a more idiomatic member selection syntax.
- The improvements to
-
Typeable improvements
- It is no longer possible to cast from
null
. - All elements of an intersection type are verified, not just the first.
- Various otherwise impossible
Typeable
instances have been excluded. - It is now possible to cast to singleton types.
- It is no longer possible to cast from
-
Added simulation of first-class literal singleton types.
Lots of new examples,
- Ensime protocol (de)serialization via type class derivation.
- Type safe structural diff via type class derivation.
- CSV (de)serialization via type class derivation.
- An example use of
Lazy
to control implicit divergence. - Examples of the new optic/prism/lens infrastructure
- An example of using case classes a la carte to automatically intern instances.
- Partitioning a list of members of an ADT via its coproduct
Generic
. - Type level FizzBuzz.