Skip to content

Commit

Permalink
Merge pull request #596 from lenguyenthanh/by-color-apply
Browse files Browse the repository at this point in the history
Only allow total function in ByColor.apply
  • Loading branch information
lenguyenthanh authored Nov 18, 2024
2 parents a7b8195 + e6c00d9 commit 72f6072
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/scala/ByColor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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(_, _))
Expand Down

0 comments on commit 72f6072

Please sign in to comment.