milessabin/shapeless — pull request #119 by alexarchambault (2014-06-25 23:43:23+00:00)
Title: Totraversable

[Only the last two commits are relevant, they rely on some elements of the first four, that are also in https://github.com/milessabin/shapeless/pull/114].

This PR mainly adds a .to[M] method on HLists (and tuples). It allows one to write things like:
val hl = a :: b :: c :: ... :: HNil
val l = hl.to[List] // List[some Lub type], should be the same type as the one inferred for List(a, b, c, ...)
val ar = hl.to[Array] // Same thing with Array - note that it also works with non covariant containers
// Also works with IndexedSeq, Set, ...

This method is added by the first relevant (actually fifth) commit of this PR.

If one wants to supply a Lub instead of the one found by the implicit ToTraversable used by .to[M], the methods .toList[Lub] and .toArray[Lub] are still there, and their implementation relies on the same implicits as .to[M] (change made by the second - or sixth - commit)

val lt = hl.toArray[SomeClass]

(Obviously, supplying a Lub to .toArray and .toList is not mandatory, and .toArray and .toList should be synonymous to .to[List] and .to[Array])