Skip to content

Commit

Permalink
Make boilerplate syntax classes extend Serializable
Browse files Browse the repository at this point in the history
Today I ran into a serializability issue when using `mapN` in a Spark
environment 😬.
  • Loading branch information
ceedubs committed May 28, 2020
1 parent a0f3534 commit 9ff69f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/semigroupal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait SemigroupalSyntax {
}
}

abstract class SemigroupalOps[F[_], A] extends Semigroupal.Ops[F, A] {
abstract class SemigroupalOps[F[_], A] extends Semigroupal.Ops[F, A] with Serializable {

@deprecated("Replaced by an apply syntax, e.g. instead of (a |@| b).map(...) use (a, b).mapN(...)", "1.0.0-MF")
final private[syntax] def |@|[B](fb: F[B]): SemigroupalBuilder[F]#SemigroupalBuilder2[A, B] =
Expand Down
8 changes: 4 additions & 4 deletions project/Boilerplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ object Boilerplate {
|
|
|@deprecated("replaced by apply syntax", "1.0.0-MF")
|private[syntax] final class SemigroupalBuilder[F[_]] {
|private[syntax] final class SemigroupalBuilder[F[_]] extends Serializable {
| def |@|[A](a: F[A]) = new SemigroupalBuilder1(a)
|
- private[syntax] final class SemigroupalBuilder$arity[${`A..N`}]($params) {
- private[syntax] final class SemigroupalBuilder$arity[${`A..N`}]($params) extends Serializable {
- $next
- def apWith[Z](f: F[(${`A..N`}) => Z])(implicit apply: Apply[F]): F[Z] = apply.ap$n(f)(${`a..n`})
- $map
Expand Down Expand Up @@ -417,7 +417,7 @@ object Boilerplate {
- implicit def catsSyntaxTuple${arity}Parallel[M[_], ${`A..N`}]($tupleTpe): Tuple${arity}ParallelOps[M, ${`A..N`}] = new Tuple${arity}ParallelOps(t$arity)
|}
|
-private[syntax] final class Tuple${arity}ParallelOps[M[_], ${`A..N`}](private val $tupleTpe) {
-private[syntax] final class Tuple${arity}ParallelOps[M[_], ${`A..N`}](private val $tupleTpe) extends Serializable {
- $parMap
- $parTupled
-}
Expand Down Expand Up @@ -487,7 +487,7 @@ object Boilerplate {
- implicit def catsSyntaxTuple${arity}Semigroupal[F[_], ${`A..N`}]($tupleTpe): Tuple${arity}SemigroupalOps[F, ${`A..N`}] = new Tuple${arity}SemigroupalOps(t$arity)
|}
|
-private[syntax] final class Tuple${arity}SemigroupalOps[F[_], ${`A..N`}](private val $tupleTpe) {
-private[syntax] final class Tuple${arity}SemigroupalOps[F[_], ${`A..N`}](private val $tupleTpe) extends Serializable {
- $map
- $contramap
- $imap
Expand Down
25 changes: 25 additions & 0 deletions tests/src/test/scala/cats/tests/SyntaxSerializationSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cats.tests

import cats.laws.discipline.SerializableTests

/**
* Test that our syntax implicits are serializable.
*/
class SyntaxSerializationSuite extends CatsSuite {
checkAll(
"Tuple3SemigroupalOps[Option, Boolean, Int, Long]",
SerializableTests.serializable(
cats.syntax.all.catsSyntaxTuple3Semigroupal[Option, Boolean, Int, Long]((None, None, None))
)
)

checkAll("SemigroupalOps[Option, Int]",
SerializableTests.serializable(cats.syntax.all.catsSyntaxSemigroupal[Option, Int](None)))

checkAll(
"Tuple3ParallelOps[Option, Boolean, Int, Long]",
SerializableTests.serializable(
cats.syntax.all.catsSyntaxTuple3Parallel[Either[String, ?], Boolean, Int, Long]((Left("a"), Left("b"), Left("c")))
)
)
}

0 comments on commit 9ff69f6

Please sign in to comment.