-
-
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
Changes from 2 commits
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] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abstract vals look suspicious a bit. And might not be necessary – since private[data] trait OneAndBinCompat0[F[_], A] {
self: OneAnd[F, A] => // allow access to `head` and `tail` from withing this trait
// no abstract `head` and `tail` should be necessary
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason I've never used a non- |
||
|
|
||
| @deprecated("Kept for binary compatibility", "2.14.0") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [question] Is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. personally I wouldn't add the deprecated and just add a comment.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a method is superceded by some other method with the same name, we usually not only make it package local, but also remove all which makes it less likely to interfere with the new method while preserving binary compatibility. I personally don't mind marking it |
||
| 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") | ||
| 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") | ||
| 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