Skip to content

Commit db44bd4

Browse files
authored
Merge pull request #4739 from kory33/oneand-typeclass-constraints
Weaken some `Alternative` constraints in `OneAnd`
2 parents fbd2ba5 + e059ed8 commit db44bd4

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

core/src/main/scala/cats/data/OneAnd.scala

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import kernel.compat.scalaVersionSpecific.*
3434
* type NonEmptyStream[A] = OneAnd[Stream, A]
3535
* }}}
3636
*/
37-
final case class OneAnd[F[_], A](head: A, tail: F[A]) {
37+
final case class OneAnd[F[_], A](head: A, tail: F[A]) extends OneAndBinCompat0[F, A] {
3838

3939
/**
4040
* Combine the head and tail into a single `F[A]` value.
4141
*/
42-
def unwrap(implicit F: Alternative[F]): F[A] =
42+
def unwrap(implicit F: NonEmptyAlternative[F]): F[A] =
4343
F.prependK(head, tail)
4444

4545
/**
@@ -53,7 +53,7 @@ final case class OneAnd[F[_], A](head: A, tail: F[A]) {
5353
/**
5454
* Append another OneAnd to this
5555
*/
56-
def combine(other: OneAnd[F, A])(implicit F: Alternative[F]): OneAnd[F, A] =
56+
def combine(other: OneAnd[F, A])(implicit F: NonEmptyAlternative[F]): OneAnd[F, A] =
5757
OneAnd(head, F.combineK(tail, other.unwrap))
5858

5959
/**
@@ -123,8 +123,18 @@ final case class OneAnd[F[_], A](head: A, tail: F[A]) {
123123
s"OneAnd(${A.show(head)}, ${FA.show(tail)})"
124124
}
125125

126+
sealed private[data] trait OneAndBinCompat0[F[_], A] { self: OneAnd[F, A] =>
127+
// Kept for binary compatibility
128+
private[data] def unwrap(F: Alternative[F]): F[A] =
129+
self.unwrap(F)
130+
131+
// Kept for binary compatibility
132+
private[data] def combine(other: OneAnd[F, A])(F: Alternative[F]): OneAnd[F, A] =
133+
self.combine(other)(F)
134+
}
135+
126136
@suppressUnusedImportWarningForScalaVersionSpecific
127-
sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 {
137+
sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 with OneAndInstancesBinCompat0 {
128138

129139
implicit def catsDataParallelForOneAnd[A, M[_]: Alternative, F0[_]: Alternative](implicit
130140
P: Parallel.Aux[M, F0]
@@ -158,13 +168,13 @@ sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 {
158168

159169
implicit def catsDataShowForOneAnd[A, F[_]](implicit A: Show[A], FA: Show[F[A]]): Show[OneAnd[F, A]] = _.show
160170

161-
implicit def catsDataSemigroupKForOneAnd[F[_]: Alternative]: SemigroupK[OneAnd[F, *]] =
171+
implicit def catsDataSemigroupKForOneAnd[F[_]: NonEmptyAlternative]: SemigroupK[OneAnd[F, *]] =
162172
new SemigroupK[OneAnd[F, *]] {
163173
def combineK[A](a: OneAnd[F, A], b: OneAnd[F, A]): OneAnd[F, A] =
164174
a.combine(b)
165175
}
166176

167-
implicit def catsDataSemigroupForOneAnd[F[_]: Alternative, A]: Semigroup[OneAnd[F, A]] =
177+
implicit def catsDataSemigroupForOneAnd[F[_]: NonEmptyAlternative, A]: Semigroup[OneAnd[F, A]] =
168178
catsDataSemigroupKForOneAnd[F].algebra
169179

170180
implicit def catsDataMonadForOneAnd[F[_]](implicit
@@ -331,4 +341,15 @@ sealed abstract private[data] class OneAndLowPriority0 extends OneAndLowPriority
331341
}
332342
}
333343

344+
sealed private[data] trait OneAndInstancesBinCompat0 { self: OneAndInstances =>
345+
346+
// Kept for binary compatibility
347+
def catsDataSemigroupKForOneAnd[F[_]](F: Alternative[F]): SemigroupK[OneAnd[F, *]] =
348+
self.catsDataSemigroupKForOneAnd[F](F)
349+
350+
// Kept for binary compatibility
351+
def catsDataSemigroupForOneAnd[F[_], A](F: Alternative[F]): Semigroup[OneAnd[F, A]] =
352+
self.catsDataSemigroupKForOneAnd[F](F).algebra
353+
}
354+
334355
object OneAnd extends OneAndInstances

0 commit comments

Comments
 (0)