-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Weaken some Alternative constraints in OneAnd
#4739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
585e755
c2d1444
af23366
175dd2a
e059ed8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,12 +34,12 @@ import kernel.compat.scalaVersionSpecific.* | |
| * type NonEmptyStream[A] = OneAnd[Stream, A] | ||
| * }}} | ||
| */ | ||
| final case class OneAnd[F[_], A](head: A, tail: F[A]) { | ||
| final case class OneAnd[F[_], A](head: A, tail: F[A]) extends OneAndBinCompat0[F, A] { | ||
|
|
||
| /** | ||
| * Combine the head and tail into a single `F[A]` value. | ||
| */ | ||
| def unwrap(implicit F: Alternative[F]): F[A] = | ||
| def unwrap(implicit F: NonEmptyAlternative[F]): F[A] = | ||
| F.prependK(head, tail) | ||
|
|
||
| /** | ||
|
|
@@ -53,7 +53,7 @@ final case class OneAnd[F[_], A](head: A, tail: F[A]) { | |
| /** | ||
| * Append another OneAnd to this | ||
| */ | ||
| def combine(other: OneAnd[F, A])(implicit F: Alternative[F]): OneAnd[F, A] = | ||
| def combine(other: OneAnd[F, A])(implicit F: NonEmptyAlternative[F]): OneAnd[F, A] = | ||
| OneAnd(head, F.combineK(tail, other.unwrap)) | ||
|
|
||
| /** | ||
|
|
@@ -123,8 +123,21 @@ final case class OneAnd[F[_], A](head: A, tail: F[A]) { | |
| s"OneAnd(${A.show(head)}, ${FA.show(tail)})" | ||
| } | ||
|
|
||
| private[data] trait OneAndBinCompat0[F[_], A] { | ||
| val head: A | ||
| val tail: F[A] | ||
|
||
|
|
||
| @deprecated("Kept for binary compatibility", "2.14.0") | ||
|
||
| private[data] def unwrap(implicit F: Alternative[F]): F[A] = | ||
| F.prependK(head, tail) | ||
|
|
||
| @deprecated("Kept for binary compatibility", "2.14.0") | ||
| private[data] def combine(other: OneAnd[F, A])(implicit F: Alternative[F]): OneAnd[F, A] = | ||
| OneAnd(head, F.combineK(tail, other.unwrap)) | ||
| } | ||
|
|
||
| @suppressUnusedImportWarningForScalaVersionSpecific | ||
| sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 { | ||
| sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 with OneAndInstancesBinCompat0 { | ||
|
|
||
| implicit def catsDataParallelForOneAnd[A, M[_]: Alternative, F0[_]: Alternative](implicit | ||
| P: Parallel.Aux[M, F0] | ||
|
|
@@ -158,13 +171,13 @@ sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 { | |
|
|
||
| implicit def catsDataShowForOneAnd[A, F[_]](implicit A: Show[A], FA: Show[F[A]]): Show[OneAnd[F, A]] = _.show | ||
|
|
||
| implicit def catsDataSemigroupKForOneAnd[F[_]: Alternative]: SemigroupK[OneAnd[F, *]] = | ||
| implicit def catsDataSemigroupKForOneAnd[F[_]: NonEmptyAlternative]: SemigroupK[OneAnd[F, *]] = | ||
| new SemigroupK[OneAnd[F, *]] { | ||
| def combineK[A](a: OneAnd[F, A], b: OneAnd[F, A]): OneAnd[F, A] = | ||
| a.combine(b) | ||
| } | ||
|
|
||
| implicit def catsDataSemigroupForOneAnd[F[_]: Alternative, A]: Semigroup[OneAnd[F, A]] = | ||
| implicit def catsDataSemigroupForOneAnd[F[_]: NonEmptyAlternative, A]: Semigroup[OneAnd[F, A]] = | ||
| catsDataSemigroupKForOneAnd[F].algebra | ||
|
|
||
| implicit def catsDataMonadForOneAnd[F[_]](implicit | ||
|
|
@@ -331,4 +344,18 @@ sealed abstract private[data] class OneAndLowPriority0 extends OneAndLowPriority | |
| } | ||
| } | ||
|
|
||
| private[data] trait OneAndInstancesBinCompat0 { | ||
|
|
||
| @deprecated("Kept for binary compatibility", "2.14.0") | ||
| private[data] def catsDataSemigroupKForOneAnd[F[_]: Alternative]: SemigroupK[OneAnd[F, *]] = | ||
| new SemigroupK[OneAnd[F, *]] { | ||
| def combineK[A](a: OneAnd[F, A], b: OneAnd[F, A]): OneAnd[F, A] = | ||
| a.combine(b) | ||
| } | ||
|
|
||
| @deprecated("Kept for binary compatibility", "2.14.0") | ||
| private[data] def catsDataSemigroupForOneAnd[F[_]: Alternative, A]: Semigroup[OneAnd[F, A]] = | ||
| catsDataSemigroupKForOneAnd[F].algebra | ||
| } | ||
|
|
||
| object OneAnd extends OneAndInstances | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question] Is this the right way to pass the MiMa check for a
case classmodification?I saw #3997 (comment) and thought that this was the (only) way, but I could not find any other place that defines a similar bincompat
trait(other thanValidatedFunctionsBinCompat0, which patches the companion rather than theValidatedclass itself).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this sealed? I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I made it
sealed: af23366