Skip to content

Commit

Permalink
Rename Serde methods for consistency with ZIO 2 (#1378)
Browse files Browse the repository at this point in the history
Renames:
* mapM -> mapZIO
* contramapM -> contramapZIO
* inmapM -> inmapZIO

The existing methods are now deprecated.

See also scala-steward-org/scala-steward#3474.

Fixes #1325.

---------

Co-authored-by: Erik van Oosten <[email protected]>
  • Loading branch information
svroonland and erikvanoosten authored Nov 12, 2024
1 parent 18aa941 commit 90f2973
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion zio-kafka/src/main/scala/zio/kafka/serde/Deserializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions zio-kafka/src/main/scala/zio/kafka/serde/Serde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion zio-kafka/src/main/scala/zio/kafka/serde/Serializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 90f2973

Please sign in to comment.