From 89a6b0bb5cb6f311130e49458dc77ec5fa2b4f86 Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Wed, 7 Oct 2020 09:21:41 +0100 Subject: [PATCH 1/2] Add methods on FunctonK to narrow input/widen output types --- core/src/main/scala/cats/arrow/FunctionK.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/scala/cats/arrow/FunctionK.scala b/core/src/main/scala/cats/arrow/FunctionK.scala index f2f6457ae1..265941586b 100644 --- a/core/src/main/scala/cats/arrow/FunctionK.scala +++ b/core/src/main/scala/cats/arrow/FunctionK.scala @@ -59,6 +59,10 @@ trait FunctionK[F[_], G[_]] extends Serializable { self => */ def and[H[_]](h: FunctionK[F, H]): FunctionK[F, Tuple2K[G, H, *]] = new FunctionK[F, Tuple2K[G, H, *]] { def apply[A](fa: F[A]): Tuple2K[G, H, A] = Tuple2K(self(fa), h(fa)) } + + def widen[G0[x] >: G[x]]: FunctionK[F, G0] = this.asInstanceOf[FunctionK[F, G0]] + + def narrow[F0[x] <: F[x]]: FunctionK[F0, G] = this.asInstanceOf[FunctionK[F0, G]] } object FunctionK extends FunctionKMacroMethods { From 57c55718faa4fa0e510089285b3117b9bd3b2872 Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Wed, 7 Oct 2020 09:24:11 +0100 Subject: [PATCH 2/2] Add scaladocs --- core/src/main/scala/cats/arrow/FunctionK.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/main/scala/cats/arrow/FunctionK.scala b/core/src/main/scala/cats/arrow/FunctionK.scala index 265941586b..4ede968fa8 100644 --- a/core/src/main/scala/cats/arrow/FunctionK.scala +++ b/core/src/main/scala/cats/arrow/FunctionK.scala @@ -60,8 +60,14 @@ trait FunctionK[F[_], G[_]] extends Serializable { self => def and[H[_]](h: FunctionK[F, H]): FunctionK[F, Tuple2K[G, H, *]] = new FunctionK[F, Tuple2K[G, H, *]] { def apply[A](fa: F[A]): Tuple2K[G, H, A] = Tuple2K(self(fa), h(fa)) } + /** + * Widens the output type of this `FunctionK` from `G` to `G0` + */ def widen[G0[x] >: G[x]]: FunctionK[F, G0] = this.asInstanceOf[FunctionK[F, G0]] + /** + * Narrows the input type of this `FunctionK` from `F` to `F0` + */ def narrow[F0[x] <: F[x]]: FunctionK[F0, G] = this.asInstanceOf[FunctionK[F0, G]] }