From b02af7d83d1120541c39e77b786e38e9ee631a1c Mon Sep 17 00:00:00 2001 From: peterneyens Date: Thu, 9 Jun 2016 16:50:09 +0200 Subject: [PATCH] Add an Unapply with the signature of Nested. To make syntax possible with Nested. --- core/src/main/scala/cats/Unapply.scala | 12 ++++++++++++ tests/src/test/scala/cats/tests/UnapplyTests.scala | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/core/src/main/scala/cats/Unapply.scala b/core/src/main/scala/cats/Unapply.scala index 0ba11bb7f2..9949c73cdd 100644 --- a/core/src/main/scala/cats/Unapply.scala +++ b/core/src/main/scala/cats/Unapply.scala @@ -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 + } } diff --git a/tests/src/test/scala/cats/tests/UnapplyTests.scala b/tests/src/test/scala/cats/tests/UnapplyTests.scala index 5569332063..6eccf76e18 100644 --- a/tests/src/test/scala/cats/tests/UnapplyTests.scala +++ b/tests/src/test/scala/cats/tests/UnapplyTests.scala @@ -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))) + } }