milessabin/shapeless — pull request #172 by alexarchambault (2014-07-13 18:17:53+00:00)
Title: HList.fill / Tuple.fill

This PR implements a fill method on the HList singleton and in a Tuple singleton, that can be used to build HList or tuples. It allows one to write:

Tuple.fill[_3]("value") :+ 2
or
Tuple.fill[_4][Option[String]](None) ++ ("a", 2) // explicitly provided upper bound instead of None.type that would have been guessed

Same thing for HList.fill.

I especially found it useful while writing code that looks like:

val p: List[...]
p.foldLeft(Tuple.fill[_3](Option.empty[String])) {
// instead of p.foldLeft((Option.empty[String], Option.empty[String], Option.empty[String]))
case ((None, None, None), item) =>
...
case ... =>
}

or

p.foldLeft(Tuple.fill[_3][Either[List[String]]](Right(Nil))) {
// instead of p.foldLeft((Right(Nil), Right(Nil), Right(Nil)): (Either[List[String]], Either[List[String]], Either[List[String]]))
case (Right(acc1), Right(acc2), Right(acc3)) =>
...
case ... =>
}