Skip to content

Commit

Permalink
Merge branch 'master' into update/scala-library-2.13.14
Browse files Browse the repository at this point in the history
  • Loading branch information
geirolz authored May 30, 2024
2 parents 1a624ad + d20933f commit 455d406
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.0"
version = "3.8.1"
style = default
maxColumn = 120
align.preset = most
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import microsites.ExtraMdFileConfig

ThisBuild / name := "fs2-rabbit"
ThisBuild / scalaVersion := "2.13.14"
ThisBuild / crossScalaVersions := List("2.12.18", "2.13.14", "3.3.1")
ThisBuild / crossScalaVersions := List("2.12.19", "2.13.14", "3.3.3")
ThisBuild / versionScheme := Some("semver-spec")
ThisBuild / organization := "dev.profunktor"
ThisBuild / homepage := Some(url("https://fs2-rabbit.profunktor.dev/"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/

package dev.profunktor.fs2rabbit.effects
import cats.{Applicative, ApplicativeThrow}
import cats.{Applicative, ApplicativeError, ApplicativeThrow, MonadError}
import cats.data.Kleisli
import dev.profunktor.fs2rabbit.model.{AmqpFieldValue, AmqpProperties, ExchangeName, RoutingKey}
import dev.profunktor.fs2rabbit.model.AmqpFieldValue._
import cats.implicits._

object EnvelopeDecoder {
object EnvelopeDecoder extends EnvelopeDecoderInstances {

def apply[F[_], A](implicit e: EnvelopeDecoder[F, A]): EnvelopeDecoder[F, A] = e

def properties[F[_]: Applicative]: EnvelopeDecoder[F, AmqpProperties] =
Expand Down Expand Up @@ -81,3 +82,16 @@ object EnvelopeDecoder {
): EnvelopeDecoder[F, Option[A]] =
Kleisli(_.properties.headers.get(name).traverse(h => F.catchNonFatal(pf(h))))
}

sealed trait EnvelopeDecoderInstances {

implicit def decoderAttempt[F[_], E: ApplicativeError[F, *], A](implicit
decoder: EnvelopeDecoder[F, A]
): EnvelopeDecoder[F, Either[E, A]] =
decoder.attempt

implicit def decoderOption[F[_], E: ApplicativeError[F, *], A](implicit
decoder: EnvelopeDecoder[F, A]
): EnvelopeDecoder[F, Option[A]] =
decoder.attempt.map(_.toOption)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ import cats.effect.unsafe.implicits.global

class EnvelopeDecoderSpec extends AsyncFunSuite {

import EnvelopeDecoder._
// Available instances of EnvelopeDecoder for any ApplicativeError[F, Throwable]
EnvelopeDecoder[Either[Throwable, *], String]
EnvelopeDecoder[SyncIO, String]
EnvelopeDecoder[EitherT[IO, String, *], String]
EnvelopeDecoder[Try, String]
EnvelopeDecoder[Try, Option[String]]
EnvelopeDecoder[Try, Either[Throwable, String]]

test("should decode a UTF-8 string") {
val msg = "hello world!"
Expand Down Expand Up @@ -86,4 +89,32 @@ class EnvelopeDecoderSpec extends AsyncFunSuite {
.unsafeToFuture()
}

test("should decode a UTF-8 string - Attempt") {
val msg = "hello world!"
val raw = msg.getBytes(StandardCharsets.UTF_8)

EnvelopeDecoder[IO, Either[Throwable, String]]
.run(
AmqpEnvelope(DeliveryTag(0L), raw, AmqpProperties.empty, ExchangeName("test"), RoutingKey("test.route"), false)
)
.flatMap { result =>
IO(assert(result == Right(msg)))
}
.unsafeToFuture()
}

test("should decode a UTF-8 string - Attempt option") {
val msg = "hello world!"
val raw = msg.getBytes(StandardCharsets.UTF_8)

EnvelopeDecoder[IO, Option[String]]
.run(
AmqpEnvelope(DeliveryTag(0L), raw, AmqpProperties.empty, ExchangeName("test"), RoutingKey("test.route"), false)
)
.flatMap { result =>
IO(assert(result == Option(msg)))
}
.unsafeToFuture()
}

}
16 changes: 8 additions & 8 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ object Dependencies {

object Version {
val cats = "2.10.0"
val catsEffect = "3.5.3"
val fs2 = "3.9.4"
val circe = "0.14.6"
val amqpClient = "5.20.0"
val logback = "1.4.14"
val catsEffect = "3.5.4"
val fs2 = "3.10.2"
val circe = "0.14.7"
val amqpClient = "5.21.0"
val logback = "1.5.6"
val monix = "3.3.0"
val zio = "1.0.18"
val zioCats = "3.2.9.1"
val scodec = "1.2.0"
val dropwizard = "4.2.25"
val collectionCompat = "2.11.0"
val collectionCompat = "2.12.0"

val kindProjector = "0.13.2"
val kindProjector = "0.13.3"

val scalaTest = "3.2.18"
val scalaCheck = "1.17.0"
val scalaCheck = "1.17.1"
val scalaTestPlusScalaCheck = "3.2.14.0"
val disciplineScalaCheck = "2.2.0"
}
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releas
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
addSbtPlugin("com.47deg" % "sbt-microsites" % "1.4.4")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.7")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.0")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.1")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3")

0 comments on commit 455d406

Please sign in to comment.