From e6c00d9ace1b836f9300738ebb1a00a54002cb9f Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Mon, 18 Nov 2024 19:58:55 +0100 Subject: [PATCH] Only allow total function in ByColor.apply --- core/src/main/scala/ByColor.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/ByColor.scala b/core/src/main/scala/ByColor.scala index a937fd3cb..f94439ab9 100644 --- a/core/src/main/scala/ByColor.scala +++ b/core/src/main/scala/ByColor.scala @@ -5,6 +5,7 @@ import cats.syntax.all.* import cats.{ Applicative, Eq, Eval, FlatMap, Functor, Monoid, Semigroupal, Traverse } import scala.annotation.targetName +import scala.util.NotGiven case class ByColor[A](white: A, black: A): @@ -97,7 +98,8 @@ object ByColor: inline def fill[A](a: A): ByColor[A] = ByColor(a, a) inline def fromPair[A](p: (A, A)): ByColor[A] = ByColor(p._1, p._2) - def apply[A](f: Color => A): ByColor[A] = ByColor(white = f(White), black = f(Black)) + def apply[A](f: Color => A)(using NotGiven[f.type <:< PartialFunction[Color, A]]): ByColor[A] = + ByColor(white = f(White), black = f(Black)) def apply[F[_], A](f: Color => F[A]): Applicative[F] ?=> F[ByColor[A]] = (f(White), f(Black)).mapN(ByColor(_, _))