Skip to content

Commit

Permalink
Merge pull request #1105 from peterneyens/nested-unapply
Browse files Browse the repository at this point in the history
Add an Unapply with the signature of Nested.
  • Loading branch information
adelbertc committed Jun 9, 2016
2 parents e78666f + b02af7d commit 8b2c42c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/scala/cats/Unapply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,16 @@ private[cats] sealed abstract class Unapply3Instances {
def TC: TC[F[AA, B, ?]] = tc
def subst: F[AA, B, C] => M[A] = identity
}

type Aux3Nested[TC[_[_]], MA, F[_[_], _[_], _], AA[_], BB[_], C] = Unapply[TC, MA] {
type M[X] = F[AA, BB, X]
type A = C
}

implicit def unapply3Nested[TC[_[_]], MA, F[_[_], _[_], _], AA[_], BB[_], C](implicit tc: TC[F[AA, BB, ?]]): Aux3Nested[TC, F[AA, BB, C], F, AA, BB, C] = new Unapply[TC, F[AA, BB, C]] {
type M[X] = F[AA, BB, X]
type A = C
def TC: TC[F[AA, BB, ?]] = tc
def subst: F[AA, BB, C] => M[C] = identity
}
}
7 changes: 7 additions & 0 deletions tests/src/test/scala/cats/tests/UnapplyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ class UnapplyTests extends CatsSuite {
}

checkAll("Unapply[Functor, Option[String]]", SerializableTests.serializable(Unapply[Functor, Option[String]]))

test("Unapply works for F[_[_], _[_], _]") {
val x: List[Option[Int]] = List(Option(1), Option(2))
val y: Nested[List, Option, Int] = Nested(x)

y.map(_ + 1).value should === (x.map(_.map(_ + 1)))
}
}

0 comments on commit 8b2c42c

Please sign in to comment.