milessabin/shapeless — pull request #24 by travisbrown (2013-02-25 20:20:17+00:00)
Title: New "normalization" type class

Added a `Normalizer` type class to support the kind of normalization discussed [here](https://groups.google.com/d/msg/shapeless-dev/HvV63toSBNM/Nv0DsuBLJzEJ) (I'm happy to resubmit this pull request with a different name if someone has a better idea than "normalize").

Also added a constraint to one of the implicits that creates `FilterAux` instances to avoid creating invalid instances like this:

```scala
implicitly[FilterAux[Foo :: Foo :: HNil, Foo, Foo :: HNil]]
```

Together these two changes allow us to solve [this problem](https://groups.google.com/d/msg/shapeless-dev/HvV63toSBNM/K84lmwSsYzwJ) very concisely:

```scala
import shapeless._

implicit class Uniqueable[L <: HList](l: L) {
def unique[A](implicit ev: FilterAux[L, A, A :: HNil]) = ev(l).head
}

class Foo; class Bar extends Foo

// These two compile:
(1 :: new Bar :: new Foo :: "a" :: HNil).unique[Bar]
(1 :: new Bar :: new Foo :: "a" :: HNil).unique[Foo]
```
But if we want to be sure that there's a unique `Foo` (including subtypes of `Foo`), we can write the following:

```scala
(1 :: new Bar :: new Foo :: "a" :: HNil).normalize[Foo].unique[Foo]
```

And we'll get a compiler error, as desired.