From 7ff1809c065a020d269bc64e34a9a83f8e2c2417 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 15 May 2021 03:15:44 -0700 Subject: [PATCH] Delete priority --- .../main/scala/cats/algebra/Priority.scala | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 algebra-core/src/main/scala/cats/algebra/Priority.scala diff --git a/algebra-core/src/main/scala/cats/algebra/Priority.scala b/algebra-core/src/main/scala/cats/algebra/Priority.scala deleted file mode 100644 index 9a22325921..0000000000 --- a/algebra-core/src/main/scala/cats/algebra/Priority.scala +++ /dev/null @@ -1,66 +0,0 @@ -package cats -package algebra - -/** - * Priority is a type class for prioritized implicit search. - * - * This type class will attempt to provide an implicit instance of `P` - * (the preferred type). If that type is not available it will - * fallback to `F` (the fallback type). If neither type is available - * then a `Priority[P, F]` instance will not be available. - * - * This type can be useful for problems where multiple algorithms can - * be used, depending on the type classes available. - */ -sealed trait Priority[+P, +F] { - - import Priority.{Fallback, Preferred} - - def fold[B](f1: P => B)(f2: F => B): B = - this match { - case Preferred(x) => f1(x) - case Fallback(y) => f2(y) - } - - def join[U >: P with F]: U = - fold(_.asInstanceOf[U])(_.asInstanceOf[U]) - - def bimap[P2, F2](f1: P => P2)(f2: F => F2): Priority[P2, F2] = - this match { - case Preferred(x) => Preferred(f1(x)) - case Fallback(y) => Fallback(f2(y)) - } - - def toEither: Either[P, F] = - fold[Either[P, F]](p => Left(p))(f => Right(f)) - - def isPreferred: Boolean = - fold(_ => true)(_ => false) - - def isFallback: Boolean = - fold(_ => false)(_ => true) - - def getPreferred: Option[P] = - fold[Option[P]](p => Some(p))(_ => None) - - def getFallback: Option[F] = - fold[Option[F]](_ => None)(f => Some(f)) -} - -object Priority extends FindPreferred { - - case class Preferred[P](get: P) extends Priority[P, Nothing] - case class Fallback[F](get: F) extends Priority[Nothing, F] - - def apply[P, F](implicit ev: Priority[P, F]): Priority[P, F] = ev -} - -private[algebra] trait FindPreferred extends FindFallback { - implicit def preferred[P](implicit ev: P): Priority[P, Nothing] = - Priority.Preferred(ev) -} - -private[algebra] trait FindFallback { - implicit def fallback[F](implicit ev: F): Priority[Nothing, F] = - Priority.Fallback(ev) -}