Skip to content

Commit

Permalink
breaking the build to show the build error of ReversedMissingMethodPr…
Browse files Browse the repository at this point in the history
…oblem
  • Loading branch information
neomaclin committed Jan 6, 2024
1 parent fb356b7 commit 31a1d66
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions std/shared/src/main/scala/cats/effect/std/PQueue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,32 +230,12 @@ trait PQueueSource[F[_], A] extends QueueSource[F, A] {
* Note: If there are multiple elements with least priority, the order in which they are
* dequeued is undefined.
*/
override def tryTakeN(maxN: Option[Int])(implicit F: Monad[F]): F[List[A]] = {
PQueueSource.assertMaxNPositive(maxN)

def loop(i: Int, limit: Int, acc: List[A]): F[List[A]] =
if (i >= limit)
F.pure(acc.reverse)
else
tryTake flatMap {
case Some(a) => loop(i + 1, limit, a :: acc)
case None => F.pure(acc.reverse)
}

maxN match {
case Some(limit) => loop(0, limit, Nil)
case None => loop(0, Int.MaxValue, Nil)
}
}
override def tryTakeN(maxN: Option[Int])(implicit F: Monad[F]): F[List[A]] =
super.tryTakeN(maxN)

}

object PQueueSource {
private def assertMaxNPositive(maxN: Option[Int]): Unit = maxN match {
case Some(n) if n <= 0 =>
throw new IllegalArgumentException(s"Provided maxN parameter must be positive, was $n")
case _ => ()
}

implicit def catsFunctorForPQueueSource[F[_]: Functor]: Functor[PQueueSource[F, *]] =
new Functor[PQueueSource[F, *]] {
Expand All @@ -273,14 +253,19 @@ object PQueueSource {

trait PQueueSink[F[_], A] extends QueueSink[F, A] {

override def tryOfferN(list: List[A])(implicit F: Monad[F]): F[List[A]] = list match {
case Nil => F.pure(list)
case h :: t =>
tryOffer(h).ifM(
tryOfferN(t),
F.pure(list)
)
}
/**
* Attempts to enqueue the given elements at the back of the queue without semantically
* blocking. If an item in the list cannot be enqueued, the remaining elements will be
* returned. This is a convenience method that recursively runs `tryOffer` and does not offer
* any additional performance benefits.
*
* @param list
* the elements to be put at the back of the queue
* @return
* an effect that contains the remaining valus that could not be offered.
*/
override def tryOfferN(list: List[A])(implicit F: Monad[F]): F[List[A]] =
super.tryOfferN(list)

}

Expand Down

0 comments on commit 31a1d66

Please sign in to comment.