From 90f297338c3adcdd6ddcc7c2721b56be57814743 Mon Sep 17 00:00:00 2001 From: svroonland Date: Tue, 12 Nov 2024 17:15:53 +0100 Subject: [PATCH] Rename Serde methods for consistency with ZIO 2 (#1378) Renames: * mapM -> mapZIO * contramapM -> contramapZIO * inmapM -> inmapZIO The existing methods are now deprecated. See also https://github.com/scala-steward-org/scala-steward/pull/3474. Fixes #1325. --------- Co-authored-by: Erik van Oosten --- .../src/main/scala/zio/kafka/serde/Deserializer.scala | 5 ++++- zio-kafka/src/main/scala/zio/kafka/serde/Serde.scala | 7 +++++-- zio-kafka/src/main/scala/zio/kafka/serde/Serializer.scala | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/zio-kafka/src/main/scala/zio/kafka/serde/Deserializer.scala b/zio-kafka/src/main/scala/zio/kafka/serde/Deserializer.scala index 3218664c4..0da1f9fe1 100644 --- a/zio-kafka/src/main/scala/zio/kafka/serde/Deserializer.scala +++ b/zio-kafka/src/main/scala/zio/kafka/serde/Deserializer.scala @@ -32,7 +32,10 @@ trait Deserializer[-R, +T] { /** * Create a deserializer for a type U based on the deserializer for type T and an effectful mapping function */ - def mapM[R1 <: R, U](f: T => RIO[R1, U]): Deserializer[R1, U] = Deserializer(deserialize(_, _, _).flatMap(f)) + def mapZIO[R1 <: R, U](f: T => RIO[R1, U]): Deserializer[R1, U] = Deserializer(deserialize(_, _, _).flatMap(f)) + + @deprecated("Use mapZIO", since = "2.9.0") + def mapM[R1 <: R, U](f: T => RIO[R1, U]): Deserializer[R1, U] = mapZIO(f) /** * When this serializer fails, attempt to deserialize with the alternative diff --git a/zio-kafka/src/main/scala/zio/kafka/serde/Serde.scala b/zio-kafka/src/main/scala/zio/kafka/serde/Serde.scala index a6bd842ad..6f0fc7ef4 100644 --- a/zio-kafka/src/main/scala/zio/kafka/serde/Serde.scala +++ b/zio-kafka/src/main/scala/zio/kafka/serde/Serde.scala @@ -38,8 +38,11 @@ trait Serde[-R, T] extends Deserializer[R, T] with Serializer[R, T] { /** * Convert to a Serde of type U with effectful transformations */ - def inmapM[R1 <: R, U](f: T => RIO[R1, U])(g: U => RIO[R1, T]): Serde[R1, U] = - Serde(mapM(f))(contramapM(g)) + def inmapZIO[R1 <: R, U](f: T => RIO[R1, U])(g: U => RIO[R1, T]): Serde[R1, U] = + Serde(mapZIO(f))(contramapZIO(g)) + + @deprecated("Use inmapZIO", since = "2.9.0") + def inmapM[R1 <: R, U](f: T => RIO[R1, U])(g: U => RIO[R1, T]): Serde[R1, U] = inmapZIO(f)(g) } object Serde extends Serdes { diff --git a/zio-kafka/src/main/scala/zio/kafka/serde/Serializer.scala b/zio-kafka/src/main/scala/zio/kafka/serde/Serializer.scala index 9d984707f..272d1cd6a 100644 --- a/zio-kafka/src/main/scala/zio/kafka/serde/Serializer.scala +++ b/zio-kafka/src/main/scala/zio/kafka/serde/Serializer.scala @@ -25,9 +25,12 @@ trait Serializer[-R, -T] { /** * Create a serializer for a type U based on the serializer for type T and an effectful mapping function */ - def contramapM[R1 <: R, U](f: U => RIO[R1, T]): Serializer[R1, U] = + def contramapZIO[R1 <: R, U](f: U => RIO[R1, T]): Serializer[R1, U] = Serializer((topic, headers, u) => f(u).flatMap(serialize(topic, headers, _))) + @deprecated("Use contramapZIO", since = "2.9.0") + def contramapM[R1 <: R, U](f: U => RIO[R1, T]): Serializer[R1, U] = contramapZIO(f) + /** * Returns a new serializer that executes its serialization function on the blocking threadpool. */