Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotContains and IsDistinct constraints for HList #548

merged 3 commits into from Mar 7, 2016


Copy link

@vpavkin vpavkin commented Feb 18, 2016

There was a conversation on gitter regarding these, but some urgent stuff weighted in short after.
So I leave it here for better times to be either merged or rejected :)

An implementation of IsDistinctConstraint without use of NotContainsConstraint can be following (with a use of ambiguous implicits trick):

trait IsDistinctConstraint[L <: HList]

object IsDistinctConstraint {
  def apply[T <: HList](implicit ev: IsDistinctConstraint[T]): IsDistinctConstraint[T] = ev

  // we have to build chain here so that ambiguous breaker works for smth like A :: B :: B :: HNil
  implicit def unique0 = new IsDistinctConstraint[HNil] {}
  implicit def unique1[H, T <: HList](implicit ev: IsDistinctConstraint[T]) = new IsDistinctConstraint[H :: T] {}

  implicit def uniqueAmb1[H <: HList, T](implicit ev: Selector[H, T]): IsDistinctConstraint[T :: H] = 
  implicit def uniqueAmb2[H <: HList, T](implicit ev: Selector[H, T]): IsDistinctConstraint[T :: H] = 

Maybe it's a better choice...

Copy link

@milessabin milessabin commented Feb 20, 2016

This looks very promising, but the RC cycle for 2.3.0 has already started so I'm afraid I'm going to have to punt it until 2.3.1.

@milessabin milessabin added the Feature label Feb 20, 2016
@milessabin milessabin added this to the shapeless-2.3.1 milestone Feb 20, 2016
Copy link
Contributor Author

@vpavkin vpavkin commented Feb 20, 2016

Sure, would be great! :)

Copy link

@milessabin milessabin commented Mar 7, 2016

LGTM! Many thanks ... merging :-)

milessabin added a commit that referenced this pull request Mar 7, 2016
NotContains and IsDistinct constraints for HList
@milessabin milessabin merged commit b64b012 into milessabin:master Mar 7, 2016
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
@vpavkin vpavkin deleted the vpavkin:hlist-is-distinct-typeclass branch Mar 7, 2016
@milessabin milessabin modified the milestone: shapeless-2.3.1 May 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.