From 9e8141158e362339b69afbce7b44305500012a73 Mon Sep 17 00:00:00 2001 From: Scala Steward <43047562+scala-steward@users.noreply.github.com> Date: Fri, 3 Nov 2023 09:38:38 +0100 Subject: [PATCH] Update scalafmt-core to 3.7.15 (#423) * Update scalafmt-core to 3.7.15 * Reformat with scalafmt 3.7.15 Executed command: scalafmt --non-interactive * Add 'Reformat with scalafmt 3.7.15' to .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 + .scalafmt.conf | 2 +- .../ocadotechnology/pass4s/circe/syntax.scala | 12 +++- .../pass4s/logging/LoggingSyntax.scala | 22 ++++-- .../pass4s/phobos/syntax.scala | 6 +- .../pass4s/s3proxy/S3Client.scala | 4 +- .../pass4s/s3proxy/S3Syntax.scala | 6 +- .../pass4s/connectors/activemq/taps.scala | 13 +++- .../pass4s/connectors/activemq/taps.scala | 13 +++- .../connectors/kinesis/KinesisConnector.scala | 5 +- .../pass4s/connectors/sns/SnsConnector.scala | 5 +- .../pass4s/connectors/sqs/SqsConnector.scala | 5 +- .../ocadotechnology/pass4s/demo/service.scala | 11 ++- .../ocadotechnology/pass4s/high/Broker.scala | 4 +- .../pass4s/kernel/Consumer.scala | 53 ++++++++++++--- .../pass4s/kernel/Sender.scala | 67 +++++++++++++++---- .../pass4s/kernel/Cogens.scala | 8 ++- .../pass4s/kernel/ConsumerOpsTests.scala | 6 +- .../pass4s/kernel/ImplicitPriorityTests.scala | 12 +++- .../connectors/kinesis/KinesisTests.scala | 13 +++- .../pass4s/util/EmbeddedJmsBroker.scala | 4 +- 21 files changed, 224 insertions(+), 49 deletions(-) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000..64b3efa7 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Scala Steward: Reformat with scalafmt 3.7.15 +0770922ed768fdc30a3ea6b07a936d1ec6e82c53 diff --git a/.scalafmt.conf b/.scalafmt.conf index 698daa3a..97ec8e21 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = "3.6.1" +version = "3.7.15" runner.dialect = scala213 maxColumn = 140 align.preset = some diff --git a/addons/circe/src/main/scala/com/ocadotechnology/pass4s/circe/syntax.scala b/addons/circe/src/main/scala/com/ocadotechnology/pass4s/circe/syntax.scala index a8a3c5f4..f0d4857c 100644 --- a/addons/circe/src/main/scala/com/ocadotechnology/pass4s/circe/syntax.scala +++ b/addons/circe/src/main/scala/com/ocadotechnology/pass4s/circe/syntax.scala @@ -36,7 +36,12 @@ object syntax { final private[syntax] class AsJsonSenderPartiallyApplied[F[_], P, A](private val sender: Sender[F, Message[P]]) extends AnyVal { @scala.annotation.nowarn("cat=unused-params") - def apply[R >: P](to: Destination[R])(implicit encoder: Encoder[A], noGroupId: GroupIdMeta.Absent[R]): Sender[F, A] = + def apply[R >: P]( + to: Destination[R] + )( + implicit encoder: Encoder[A], + noGroupId: GroupIdMeta.Absent[R] + ): Sender[F, A] = sender.contramap(JsonMessage(_, to).widen) } @@ -101,7 +106,10 @@ object syntax { implicit final class ConsumerCirceExtensions[F[_], A](private val consumer: Consumer[F, A]) extends AnyVal { - def asJsonConsumer[B: Decoder](implicit M: MonadError[F, _ >: io.circe.Error], ev: A <:< Payload): Consumer[F, B] = + def asJsonConsumer[B: Decoder]( + implicit M: MonadError[F, _ >: io.circe.Error], + ev: A <:< Payload + ): Consumer[F, B] = consumer.mapM(msg => decode[B](msg.text).liftTo[F]) def asJsonConsumerWithMessage[B: Decoder]( diff --git a/addons/logging/src/main/scala/com/ocadotechnology/pass4s/logging/LoggingSyntax.scala b/addons/logging/src/main/scala/com/ocadotechnology/pass4s/logging/LoggingSyntax.scala index 5a43eacf..282da396 100644 --- a/addons/logging/src/main/scala/com/ocadotechnology/pass4s/logging/LoggingSyntax.scala +++ b/addons/logging/src/main/scala/com/ocadotechnology/pass4s/logging/LoggingSyntax.scala @@ -38,7 +38,10 @@ object syntax { implicit final class LoggingSenderSyntax[F[_], P](private val underlying: Sender[F, Message[P]]) extends AnyVal { - def logged(implicit logger: Logger[F], F: MonadCancelThrow[F]): Sender[F, Message[P]] = { + def logged( + implicit logger: Logger[F], + F: MonadCancelThrow[F] + ): Sender[F, Message[P]] = { val logBefore = Sender.fromFunction[F, Message[P]] { msg => logger.trace(s"Sending message to destination [${msg.destination}]: [${msg.payload}]") } @@ -54,7 +57,12 @@ object syntax { implicit final class LoggingConsumerSyntax[F[_], A](private val underlying: Consumer[F, Payload]) extends AnyVal { - def logged[P](source: Source[P])(implicit logger: Logger[F], F: MonadCancelThrow[F]): Consumer[F, Payload] = + def logged[P]( + source: Source[P] + )( + implicit logger: Logger[F], + F: MonadCancelThrow[F] + ): Consumer[F, Payload] = underlying .surroundAll { run => logger.info(s"Starting consumer from [$source]") *> run.guaranteeCase { @@ -76,7 +84,10 @@ object syntax { implicit final class LoggingBrokerSyntax[F[_], P](private val underlying: Broker[F, P]) extends AnyVal { - def logged(implicit logger: Logger[F], F: MonadCancelThrow[F]): Broker[F, P] = + def logged( + implicit logger: Logger[F], + F: MonadCancelThrow[F] + ): Broker[F, P] = new Broker[F, P] { override def consumer[R >: P](source: Source[R]): Consumer[F, Payload] = underlying.consumer(source).logged(source) @@ -89,7 +100,10 @@ object syntax { implicit final class ConnectorLoggingSyntax[F[_], P](val self: Connector[F, P]) extends AnyVal { - def logged(implicit logger: Logger[F], F: Monad[F]): Connector.Aux[F, P, self.Raw] = + def logged( + implicit logger: Logger[F], + F: Monad[F] + ): Connector.Aux[F, P, self.Raw] = new Connector[F, P] { type Raw = self.Raw val underlying: self.Raw = self.underlying diff --git a/addons/phobos/src/main/scala/com/ocadotechnology/pass4s/phobos/syntax.scala b/addons/phobos/src/main/scala/com/ocadotechnology/pass4s/phobos/syntax.scala index 24b646fa..6a3dfb2d 100644 --- a/addons/phobos/src/main/scala/com/ocadotechnology/pass4s/phobos/syntax.scala +++ b/addons/phobos/src/main/scala/com/ocadotechnology/pass4s/phobos/syntax.scala @@ -108,8 +108,12 @@ object syntax { } implicit final class ConsumeXmlMessageSyntax[F[_]](private val consumer: Consumer[F, String]) { - def asXmlConsumer[A: XmlDecoder](implicit M: MonadError[F, _ >: DecodingError]): Consumer[F, A] = + + def asXmlConsumer[A: XmlDecoder]( + implicit M: MonadError[F, _ >: DecodingError] + ): Consumer[F, A] = consumer.mapM(XmlDecoder[A].decode(_).liftTo[F]) + } implicit final class ConsumeXmlGenericMessageSyntax[F[_], A](private val consumer: Consumer[F, A]) { diff --git a/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Client.scala b/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Client.scala index 0cfabc2a..ee70216c 100644 --- a/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Client.scala +++ b/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Client.scala @@ -43,7 +43,9 @@ trait S3Client[F[_]] { object S3Client { - def apply[F[_]](implicit ev: S3Client[F]): S3Client[F] = ev + def apply[F[_]]( + implicit ev: S3Client[F] + ): S3Client[F] = ev def usingBuilder[F[_]: Async]( s3Builder: S3AsyncClientBuilder diff --git a/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Syntax.scala b/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Syntax.scala index cabf991c..dde07165 100644 --- a/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Syntax.scala +++ b/addons/s3proxy/src/main/scala/com/ocadotechnology/pass4s/s3proxy/S3Syntax.scala @@ -108,7 +108,11 @@ object syntax { message = s3.replacePointerWithPayload(config, msg, payload) } yield message - private def removeDataFromS3(pointer: PayloadS3Pointer)(implicit s3Client: S3Client[F]): F[Unit] = + private def removeDataFromS3( + pointer: PayloadS3Pointer + )( + implicit s3Client: S3Client[F] + ): F[Unit] = s3Client.deleteObject(pointer.s3BucketName, pointer.s3Key) } diff --git a/connectors/activemq-pekko/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala b/connectors/activemq-pekko/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala index 4a6260aa..f369e317 100644 --- a/connectors/activemq-pekko/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala +++ b/connectors/activemq-pekko/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala @@ -40,8 +40,13 @@ private[activemq] object taps { implicit class AkkaSourceDsl[A, M](source: Graph[SourceShape[A], M]) { - def toStream[F[_]: Async](onMaterialization: M => Unit = _ => ())(implicit materializer: Materializer): Stream[F, A] = + def toStream[F[_]: Async]( + onMaterialization: M => Unit = _ => () + )( + implicit materializer: Materializer + ): Stream[F, A] = akkaSourceToFs2Stream(source)(onMaterialization) + } implicit class AkkaFlowDsl[A, B, M](flow: Graph[FlowShape[A, B], M]) { @@ -141,7 +146,11 @@ private[activemq] object taps { } } - private def subscriberStream[F[_], A](subscriber: SinkQueueWithCancel[A])(implicit F: Async[F]): Stream[F, A] = { + private def subscriberStream[F[_], A]( + subscriber: SinkQueueWithCancel[A] + )( + implicit F: Async[F] + ): Stream[F, A] = { val pull = Async[F].fromFuture(F.delay(subscriber.pull())) val cancel = F.delay(subscriber.cancel()) Stream.repeatEval(pull).unNoneTerminate.onFinalize(cancel) diff --git a/connectors/activemq/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala b/connectors/activemq/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala index ea91f377..32c8880a 100644 --- a/connectors/activemq/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala +++ b/connectors/activemq/src/main/scala/com/ocadotechnology/pass4s/connectors/activemq/taps.scala @@ -40,8 +40,13 @@ private[activemq] object taps { implicit class AkkaSourceDsl[A, M](source: Graph[SourceShape[A], M]) { - def toStream[F[_]: Async](onMaterialization: M => Unit = _ => ())(implicit materializer: Materializer): Stream[F, A] = + def toStream[F[_]: Async]( + onMaterialization: M => Unit = _ => () + )( + implicit materializer: Materializer + ): Stream[F, A] = akkaSourceToFs2Stream(source)(onMaterialization) + } implicit class AkkaFlowDsl[A, B, M](flow: Graph[FlowShape[A, B], M]) { @@ -141,7 +146,11 @@ private[activemq] object taps { } } - private def subscriberStream[F[_], A](subscriber: SinkQueueWithCancel[A])(implicit F: Async[F]): Stream[F, A] = { + private def subscriberStream[F[_], A]( + subscriber: SinkQueueWithCancel[A] + )( + implicit F: Async[F] + ): Stream[F, A] = { val cancel = F.delay(subscriber.cancel()) val pull = Async[F].fromFutureCancelable(F.delay((subscriber.pull(), cancel))) Stream.repeatEval(pull).unNoneTerminate.onFinalize(cancel) diff --git a/connectors/kinesis/src/main/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisConnector.scala b/connectors/kinesis/src/main/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisConnector.scala index d7012fd4..dd2704a9 100644 --- a/connectors/kinesis/src/main/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisConnector.scala +++ b/connectors/kinesis/src/main/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisConnector.scala @@ -56,7 +56,10 @@ trait KinesisAttributesProvider[F[_]] { } object KinesisAttributesProvider { - def apply[F[_]](implicit ev: KinesisAttributesProvider[F]): KinesisAttributesProvider[F] = ev + + def apply[F[_]]( + implicit ev: KinesisAttributesProvider[F] + ): KinesisAttributesProvider[F] = ev def default[F[_]: Sync]: KinesisAttributesProvider[F] = (payload: Payload, _: KinesisDestination) => diff --git a/connectors/sns/src/main/scala/com/ocadotechnology/pass4s/connectors/sns/SnsConnector.scala b/connectors/sns/src/main/scala/com/ocadotechnology/pass4s/connectors/sns/SnsConnector.scala index 066c358f..0b865a3d 100644 --- a/connectors/sns/src/main/scala/com/ocadotechnology/pass4s/connectors/sns/SnsConnector.scala +++ b/connectors/sns/src/main/scala/com/ocadotechnology/pass4s/connectors/sns/SnsConnector.scala @@ -86,7 +86,10 @@ trait SnsAttributesProvider[F[_]] { } object SnsAttributesProvider { - def apply[F[_]](implicit ev: SnsAttributesProvider[F]): SnsAttributesProvider[F] = ev + + def apply[F[_]]( + implicit ev: SnsAttributesProvider[F] + ): SnsAttributesProvider[F] = ev def default[F[_]: MonadThrow]: SnsAttributesProvider[F] = new SnsAttributesProvider[F] { diff --git a/connectors/sqs/src/main/scala/com/ocadotechnology/pass4s/connectors/sqs/SqsConnector.scala b/connectors/sqs/src/main/scala/com/ocadotechnology/pass4s/connectors/sqs/SqsConnector.scala index 21352455..04dca453 100644 --- a/connectors/sqs/src/main/scala/com/ocadotechnology/pass4s/connectors/sqs/SqsConnector.scala +++ b/connectors/sqs/src/main/scala/com/ocadotechnology/pass4s/connectors/sqs/SqsConnector.scala @@ -171,7 +171,10 @@ trait SqsAttributesProvider[F[_]] { } object SqsAttributesProvider { - def apply[F[_]](implicit ev: SqsAttributesProvider[F]): SqsAttributesProvider[F] = ev + + def apply[F[_]]( + implicit ev: SqsAttributesProvider[F] + ): SqsAttributesProvider[F] = ev def default[F[_]: MonadThrow]: SqsAttributesProvider[F] = new SqsAttributesProvider[F] { diff --git a/demo/src/main/scala/com/ocadotechnology/pass4s/demo/service.scala b/demo/src/main/scala/com/ocadotechnology/pass4s/demo/service.scala index 4169837d..3e58747c 100644 --- a/demo/src/main/scala/com/ocadotechnology/pass4s/demo/service.scala +++ b/demo/src/main/scala/com/ocadotechnology/pass4s/demo/service.scala @@ -28,6 +28,13 @@ trait MyService[F[_]] { } object MyService { - def apply[F[_]](implicit F: MyService[F]): F.type = F - def instance[F[_]](implicit sender: Sender[F, Int]): MyService[F] = () => sender.sendOne(42) + + def apply[F[_]]( + implicit F: MyService[F] + ): F.type = F + + def instance[F[_]]( + implicit sender: Sender[F, Int] + ): MyService[F] = () => sender.sendOne(42) + } diff --git a/high/src/main/scala/com/ocadotechnology/pass4s/high/Broker.scala b/high/src/main/scala/com/ocadotechnology/pass4s/high/Broker.scala index fac9d275..9176d13a 100644 --- a/high/src/main/scala/com/ocadotechnology/pass4s/high/Broker.scala +++ b/high/src/main/scala/com/ocadotechnology/pass4s/high/Broker.scala @@ -41,7 +41,9 @@ trait Broker[F[_], +P] { object Broker { - def apply[F[_], P](implicit ev: Broker[F, P]): ev.type = ev + def apply[F[_], P]( + implicit ev: Broker[F, P] + ): ev.type = ev def fromConnector[F[_]: Async, P](connector: Connector[F, P]): Broker[F, P] = new Broker[F, P] { diff --git a/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Consumer.scala b/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Consumer.scala index ffdae1f6..6457cdfa 100644 --- a/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Consumer.scala +++ b/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Consumer.scala @@ -115,7 +115,10 @@ trait Consumer[F[_], +A] extends ((A => F[Unit]) => F[Unit]) with Serializable { } object Consumer extends ConsumerInstances { - def apply[F[_], A](implicit C: Consumer[F, A]): Consumer[F, A] = C + + def apply[F[_], A]( + implicit C: Consumer[F, A] + ): Consumer[F, A] = C /** A consumer that waits for processing of one message (and finalization of its resources), then takes another message from the stream of * resources. Failures that happen in the message handler are caught and used to rollback the message being processed. @@ -254,49 +257,81 @@ object Consumer extends ConsumerInstances { * are reported normally and have the same impact on the consumer's process as usual processing errors would, meaning they also usually * trigger a rollback. */ - def mapM[B](f: A => F[B])(implicit F: FlatMap[F]): Consumer[F, B] = + def mapM[B]( + f: A => F[B] + )( + implicit F: FlatMap[F] + ): Consumer[F, B] = handler => self.consume(f >=> handler) /** Allows to filter certain messages and execute an effect while doing it. * * For filtering without an effect use [[functorFilter]] instance. */ - def evalMapFilter[B](f: A => F[Option[B]])(implicit F: Monad[F]): Consumer[F, B] = + def evalMapFilter[B]( + f: A => F[Option[B]] + )( + implicit F: Monad[F] + ): Consumer[F, B] = Consumer.fromFunction[F, B](handler => self.consume(f(_).flatMap(_.fold(Applicative[F].unit)(handler)))) /** Similar to [[mapM()]], but discards the result of the tapped effect. */ - def contraTapM(f: A => F[Unit])(implicit F: FlatMap[F]): Consumer[F, A] = + def contraTapM( + f: A => F[Unit] + )( + implicit F: FlatMap[F] + ): Consumer[F, A] = handler => self.consume(a => f(a).flatTap(_ => handler(a))) /** For every message, executes provided finalization action that takes the original message as an input. Useful for performing cleanup * after the transaction has been completed successfuly. Note that this behaves the same way finalizers would do. The earliest added * action is executed the last due to the nature of function composition. */ - def afterEach(f: A => F[Unit])(implicit F: FlatMap[F]): Consumer[F, A] = + def afterEach( + f: A => F[Unit] + )( + implicit F: FlatMap[F] + ): Consumer[F, A] = use => self.consume(msg => use(msg) >> f(msg)) /** For every message, creates an artificial consumer that only handles that one message, and runs it through the given function. This * follows [[Consumer#flatMap]] semantics, so while the consumer of `B` is busy processing, no further messages will be received by * `self`. */ - def selfProduct[B](f: Consumer[F, A] => Consumer[F, B])(implicit F: Defer[F]): Consumer[F, (A, B)] = + def selfProduct[B]( + f: Consumer[F, A] => Consumer[F, B] + )( + implicit F: Defer[F] + ): Consumer[F, (A, B)] = self.mproduct(f.compose(Consumer.one[F, A])) /** Uses this consumer as a source until completion, then it switches to the second consumer. */ - def zip(another: Consumer[F, A])(implicit F: Apply[F]): Consumer[F, A] = + def zip( + another: Consumer[F, A] + )( + implicit F: Apply[F] + ): Consumer[F, A] = handleA => self.consume(handleA) *> another.consume(handleA) /** Merges the two consumers by returning one which will run them concurrently, with the same handler. No synchronization between * underlying consumers is involved - they will run completely independently. */ - def parZip(another: Consumer[F, A])(implicit F: NonEmptyParallel[F]): Consumer[F, A] = + def parZip( + another: Consumer[F, A] + )( + implicit F: NonEmptyParallel[F] + ): Consumer[F, A] = handleA => F.parProductR(self.consume(handleA))(another.consume(handleA)) + } // For laws. Mortals probably won't have a usecase for this. - implicit def eq[F[_], A](implicit equalFunction: Eq[(A => F[Unit]) => F[Unit]]): Eq[Consumer[F, A]] = equalFunction.narrow + implicit def eq[F[_], A]( + implicit equalFunction: Eq[(A => F[Unit]) => F[Unit]] + ): Eq[Consumer[F, A]] = equalFunction.narrow + } // low-priority instances. See Sender companion traits to understand the order they need to be defined in. diff --git a/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Sender.scala b/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Sender.scala index 98f0955f..f0b722c8 100644 --- a/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Sender.scala +++ b/kernel/src/main/scala/com/ocadotechnology/pass4s/kernel/Sender.scala @@ -91,7 +91,9 @@ object Sender extends SenderInstances { /** A helper that brings in the implicit Sender[F, A] in scope. The type is more precise than just Sender[F, A], so that it can keep the * type of e.g. [[RefSender]]. */ - def apply[F[_], A](implicit S: Sender[F, A]): S.type = S + def apply[F[_], A]( + implicit S: Sender[F, A] + ): S.type = S /** Helper for defining senders from a function that performs the send. */ @@ -146,17 +148,29 @@ object Sender extends SenderInstances { /** Adds an additional layer of processing before the mesage is sent - for example, logging. The result of `f` is the message that'll be * sent using the underlying sender. */ - def contramapM[B](f: B => F[A])(implicit F: FlatMap[F]): Sender[F, B] = + def contramapM[B]( + f: B => F[A] + )( + implicit F: FlatMap[F] + ): Sender[F, B] = fromFunction(f(_).flatMap(self.sendOne)) /** Alias for [[contramapM]]. */ - def prepareF[B](f: B => F[A])(implicit F: FlatMap[F]): Sender[F, B] = + def prepareF[B]( + f: B => F[A] + )( + implicit F: FlatMap[F] + ): Sender[F, B] = contramapM(f) /** Sends all messages in a traversable/foldable instance. */ - def sendAll[G[_]: Foldable](messages: G[A])(implicit F: Applicative[F]): F[Unit] = + def sendAll[G[_]: Foldable]( + messages: G[A] + )( + implicit F: Applicative[F] + ): F[Unit] = messages.traverse_(self.sendOne) /** This can be used together with [[Sender.writer]] or [[Sender.chainWriter]]: After you've sent some messages with a writer sender, @@ -164,7 +178,11 @@ object Sender extends SenderInstances { * * Also see [[sendWrittenK]]. */ - def sendWritten[Log[_]: Foldable, B](result: WriterT[F, Log[A], B])(implicit F: Monad[F]): F[B] = + def sendWritten[Log[_]: Foldable, B]( + result: WriterT[F, Log[A], B] + )( + implicit F: Monad[F] + ): F[B] = result.run.flatMap { case (log, result) => self.sendAll(log).as(result) } @@ -172,7 +190,9 @@ object Sender extends SenderInstances { /** Like [[sendWritten]], but might be more convenient if you need a [[cats.arrow.FunctionK]]. See demos/examples for how it can be used * with a composition of WriterT and a database transaction. */ - def sendWrittenK[Log[_]: Foldable](implicit F: Monad[F]): WriterT[F, Log[A], *] ~> F = + def sendWrittenK[Log[_]: Foldable]( + implicit F: Monad[F] + ): WriterT[F, Log[A], *] ~> F = new (WriterT[F, Log[A], *] ~> F) { def apply[B](fa: WriterT[F, Log[A], B]): F[B] = sendWritten(fa) } @@ -180,24 +200,40 @@ object Sender extends SenderInstances { /** Ignores messages that don't pass the filter. If you add a logging middleware on top of this, the messages filtered out might still * be seen, but they will never reach the underlying sender. */ - def filter(f: A => Boolean)(implicit F: InvariantMonoidal[F]): Sender[F, A] = + def filter( + f: A => Boolean + )( + implicit F: InvariantMonoidal[F] + ): Sender[F, A] = contramapFilter(_.some.filter(f)) /** Like [[filter]], but allows effects. */ - def filterM(f: A => F[Boolean])(implicit F: Monad[F]): Sender[F, A] = + def filterM( + f: A => F[Boolean] + )( + implicit F: Monad[F] + ): Sender[F, A] = contramapFilterM { a => f(a).map(_.guard[Option].as(a)) } /** Like [[filter]], but allows additionally transforming the message in an Option - e.g. for parsing. */ - def contramapFilter[B](f: B => Option[A])(implicit F: InvariantMonoidal[F]): Sender[F, B] = + def contramapFilter[B]( + f: B => Option[A] + )( + implicit F: InvariantMonoidal[F] + ): Sender[F, B] = fromFunction(f(_).fold(F.unit)(self.sendOne)) /** Like [[contramapFilter]], but allows an effectful filter. */ - def contramapFilterM[B](f: B => F[Option[A]])(implicit F: Monad[F]): Sender[F, B] = + def contramapFilterM[B]( + f: B => F[Option[A]] + )( + implicit F: Monad[F] + ): Sender[F, B] = fromFunction(f(_).flatMap(_.fold(F.unit)(self.sendOne))) /** The dual to [[Sender.or]] - sends both parts of the tuple to the right underlying sender ([[self]] or [[another]], based on the @@ -205,7 +241,11 @@ object Sender extends SenderInstances { * * This is the same as .tupled from Cats syntax. */ - def and[B](another: Sender[F, B])(implicit F: Apply[F]): Sender[F, (A, B)] = + def and[B]( + another: Sender[F, B] + )( + implicit F: Apply[F] + ): Sender[F, (A, B)] = Sender.fromFunction { case (a, b) => self.sendOne(a) *> another.sendOne(b) } @@ -222,7 +262,10 @@ object Sender extends SenderInstances { } // For laws, mostly - implicit def eq[F[_], A](implicit equalFunction: Eq[A => F[Unit]]): Eq[Sender[F, A]] = equalFunction.narrow + implicit def eq[F[_], A]( + implicit equalFunction: Eq[A => F[Unit]] + ): Eq[Sender[F, A]] = equalFunction.narrow + } /** See [[Sender.testing]]. diff --git a/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/Cogens.scala b/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/Cogens.scala index a790a7cd..ba20aa2a 100644 --- a/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/Cogens.scala +++ b/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/Cogens.scala @@ -20,11 +20,15 @@ import org.scalacheck.Cogen object Cogens { - implicit def cogenSender[F[_], A](implicit cogenFunction: Cogen[A => F[Unit]]): Cogen[Sender[F, A]] = + implicit def cogenSender[F[_], A]( + implicit cogenFunction: Cogen[A => F[Unit]] + ): Cogen[Sender[F, A]] = cogenFunction .contramap(_.sendOne) - implicit def cogenConsumer[F[_], A](implicit cogenFunction: Cogen[(A => F[Unit]) => F[Unit]]): Cogen[Consumer[F, A]] = + implicit def cogenConsumer[F[_], A]( + implicit cogenFunction: Cogen[(A => F[Unit]) => F[Unit]] + ): Cogen[Consumer[F, A]] = cogenFunction .contramap(_.consume) diff --git a/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ConsumerOpsTests.scala b/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ConsumerOpsTests.scala index ad2a878e..162a4055 100644 --- a/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ConsumerOpsTests.scala +++ b/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ConsumerOpsTests.scala @@ -134,7 +134,11 @@ object ConsumerOpsTests extends SimpleMutableIOSuite with Checkers { messages: List[Int], isValid: Int => Boolean ) => - def message(i: Int)(implicit sender: Sender[IO, Int]): Resource[IO, Int] = + def message( + i: Int + )( + implicit sender: Sender[IO, Int] + ): Resource[IO, Int] = Resource.make( sender.contramap(open).sendOne(i).as(i) )(sender.contramap(close).sendOne) diff --git a/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ImplicitPriorityTests.scala b/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ImplicitPriorityTests.scala index 53e85645..789b40ee 100644 --- a/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ImplicitPriorityTests.scala +++ b/kernel/src/test/scala/com/ocadotechnology/pass4s/kernel/ImplicitPriorityTests.scala @@ -40,7 +40,11 @@ object ImplicitPriorityTests { def functorK[A]: FunctorK[Sender[*[_], A]] = implicitly def contravariant[F[_]]: Contravariant[Sender[F, *]] = implicitly def semigroup[F[_]: Apply, A]: Semigroup[Sender[F, A]] = implicitly - def eq[F[_], A](implicit equalFunction: Eq[A => F[Unit]]): Eq[Sender[F, A]] = implicitly + + def eq[F[_], A]( + implicit equalFunction: Eq[A => F[Unit]] + ): Eq[Sender[F, A]] = implicitly + } class senderLevel1 { @@ -57,7 +61,11 @@ object ImplicitPriorityTests { def invariantK[A]: InvariantK[Consumer[*[_], A]] = implicitly def functor[F[_]]: Functor[Consumer[F, *]] = implicitly def functorFilter[F[_]: InvariantMonoidal]: FunctorFilter[Consumer[F, *]] = implicitly - def eq[F[_], A](implicit equalFunction: Eq[(A => F[Unit]) => F[Unit]]): Eq[Consumer[F, A]] = implicitly + + def eq[F[_], A]( + implicit equalFunction: Eq[(A => F[Unit]) => F[Unit]] + ): Eq[Consumer[F, A]] = implicitly + } class consumerLevel1 { diff --git a/src/it/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisTests.scala b/src/it/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisTests.scala index 24529916..d1977b1d 100644 --- a/src/it/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisTests.scala +++ b/src/it/scala/com/ocadotechnology/pass4s/connectors/kinesis/KinesisTests.scala @@ -68,7 +68,11 @@ object KinesisTests extends MutableIOSuite { } } - private def getShardIterator(streamName: String)(implicit kinesisClient: KinesisAsyncClientOp[IO]): IO[String] = + private def getShardIterator( + streamName: String + )( + implicit kinesisClient: KinesisAsyncClientOp[IO] + ): IO[String] = kinesisClient .getShardIterator( GetShardIteratorRequest @@ -80,6 +84,11 @@ object KinesisTests extends MutableIOSuite { ) .map(_.shardIterator()) - private def getRecords(shardIterator: String)(implicit kinesisClient: KinesisAsyncClientOp[IO]): IO[List[Record]] = + private def getRecords( + shardIterator: String + )( + implicit kinesisClient: KinesisAsyncClientOp[IO] + ): IO[List[Record]] = kinesisClient.getRecords(GetRecordsRequest.builder().shardIterator(shardIterator).build()).map(_.records().asScala.toList) + } diff --git a/src/it/scala/com/ocadotechnology/pass4s/util/EmbeddedJmsBroker.scala b/src/it/scala/com/ocadotechnology/pass4s/util/EmbeddedJmsBroker.scala index 1c279925..c863ce11 100644 --- a/src/it/scala/com/ocadotechnology/pass4s/util/EmbeddedJmsBroker.scala +++ b/src/it/scala/com/ocadotechnology/pass4s/util/EmbeddedJmsBroker.scala @@ -52,7 +52,9 @@ object EmbeddedJmsBroker { JmsConnector.singleBroker[IO](embeddedAMQConnectionFactory) } - def createBrokerAndConnectToIt(implicit logger: Logger[IO]): Resource[IO, JmsConnector[IO]] = + def createBrokerAndConnectToIt( + implicit logger: Logger[IO] + ): Resource[IO, JmsConnector[IO]] = for { implicit0(as: ActorSystem) <- actorSystemResource brokerName <- Resource.eval(IO(Random.alphanumeric.take(8).mkString)).map(randomSuffix => s"broker-$randomSuffix")