From 0a07a2c8720ceffeeeafa53524350725203a44f2 Mon Sep 17 00:00:00 2001 From: Vladislav Ugryumov Date: Wed, 29 Nov 2023 01:32:05 +0300 Subject: [PATCH 1/9] logging - scala3 support Co-authored-by: Vadim Chelyshov --- build.sbt | 42 ++++--- .../tofu/common/derived/display.scala | 8 +- .../tofu/data/derived/InitDerivation.scala | 8 +- .../tofu/data/derived/Merge.scala | 8 +- .../tofu/data/derived/MerkatorFromCats.scala | 2 +- .../tofu/data/derived/package.scala | 0 .../higherKind/derived/ContextEmbed.scala | 0 .../tofu/higherKind/derived/derived.scala | 0 .../tofu/syntax/merge.scala | 0 .../tofu/common/derived/DisplaySpec.scala | 0 .../tofu/data/derived/MergeSuite.scala | 0 .../tofu/higherKind/derived/EmbedSuite.scala | 0 .../derived/RepresentableKSuite.scala | 0 .../derived/RepresentableKVarArgSuite.scala | 0 .../main/scala-2/tofu/higherKind/Defs.scala | 5 - .../scala/tofu/higherKind/Function2K.scala | 2 - .../main/scala/tofu/higherKind/package.scala | 2 + .../{loggable.scala => DerivationImpl.scala} | 18 +-- .../tofu/logging/derivation/masking.scala | 2 +- .../tofu/logging/derivation/package.scala | 7 +- .../tofu/logging/derivation/show.scala | 10 +- .../logging/derivation/DerivationImpl.scala | 57 ++++++++++ .../tofu/logging/derivation/masking.scala | 94 ++++++++++++++++ .../tofu/logging/derivation/package.scala | 23 ++++ .../tofu/logging/derivation/annotations.scala | 0 .../tofu/logging/derivation/loggable.scala | 3 + .../logging/derivation/LoggingMidSuite.scala | 16 ++- .../test/scala-3/DerivedLoggableSuite.scala | 92 ++++++++++++++++ .../logging/LoggingMidMacroInstances.scala | 7 ++ .../LoggingRepresentableKInstances.scala | 8 ++ ...erviceLoggingRepresentableKInstances.scala | 14 +++ .../LogsRepresentableKInstances.scala | 18 +++ ...ion.scala => LocationMacroInstances.scala} | 22 +--- .../main/scala-2/tofu/logging/package.scala | 5 - .../logging/LoggingMidMacroInstances.scala | 4 + .../LoggingRepresentableKInstances.scala | 16 +++ .../main/scala-3/tofu/logging/LogsVOps.scala | 9 ++ ...erviceLoggingRepresentableKInstances.scala | 4 + .../LogsRepresentableKInstances.scala | 5 + .../location/LocationMacroInstances.scala | 58 ++++++++++ .../tofu/logging/LogAnnotation.scala | 2 +- .../tofu/logging/LogRenderer.scala | 0 .../tofu/logging/LogTree.scala | 0 .../tofu/logging/Loggable.scala | 6 +- .../tofu/logging/LoggableContext.scala | 0 .../tofu/logging/LoggableInstances.scala | 10 +- .../tofu/logging/LoggedValue.scala | 8 +- .../tofu/logging/Logging.scala | 24 ++-- .../tofu/logging/LoggingCompanion.scala | 43 ++++---- .../tofu/logging/LoggingMid.scala | 12 +- .../tofu/logging/Logs.scala | 9 +- .../tofu/logging/TethysBuilder.scala | 0 .../tofu/logging/atom/AtomLogger.scala | 0 .../tofu/logging/bi/LoggingBiCompanion.scala | 19 ++-- .../tofu/logging/bi/LoggingBiMid.scala | 0 .../logging/builder/LoggingBiMidBuilder.scala | 18 +-- .../logging/builder/LoggingMidBuilder.scala | 43 ++++---- .../tofu/logging/impl/ArgsLoggable.scala | 2 + .../tofu/logging/impl/CachedLogs.scala | 2 +- .../logging/impl/ComposedLoggedValue.scala | 0 .../logging/impl/ContextLoggingImpl.scala | 2 +- .../tofu/logging/impl/ContextMarker.scala | 0 .../logging/impl/ContextSyncLoggingImpl.scala | 2 +- .../tofu/logging/impl/ContramapLoggable.scala | 0 .../tofu/logging/impl/EmbedLogging.scala | 0 .../tofu/logging/impl/EmptyLoggable.scala | 0 .../tofu/logging/impl/FilterLoggable.scala | 0 .../tofu/logging/impl/HiddenLoggable.scala | 0 .../tofu/logging/impl/LoggingImpl.scala | 0 .../logging/impl/LoggingMidFunctions.scala | 15 ++- .../tofu/logging/impl/NamedLoggable.scala | 0 .../tofu/logging/impl/PlusLoggable.scala | 0 .../tofu/logging/impl/SingletonLoggable.scala | 0 .../tofu/logging/impl/SyncLogging.scala | 2 +- .../logging/impl/UniversalEmbedLogs.scala | 1 + .../tofu/logging/impl/UniversalLogging.scala | 3 +- .../tofu/logging/internal/LogsInstances.scala | 34 ++---- .../internal/LogsInvariantSyntax.scala | 22 ++-- .../tofu/logging/location/Location.scala | 11 ++ .../src/main/scala/tofu/logging/package.scala | 7 ++ .../tofu/syntax/location.scala | 0 .../tofu/syntax/logRenderer.scala | 0 .../tofu/syntax/loggable.scala | 0 .../tofu/syntax/logging.scala | 0 .../tofu/logging/LoggableContextSuite.scala | 20 ---- .../tofu/logging/LogTreeSuite.scala | 2 +- .../tofu/logging/LoggableContextSuite.scala | 23 ++++ .../tofu/logging/LoggableSuite.scala | 0 .../tofu/logging/LoggingSuite.scala | 2 +- .../NamedLoggableCompositionSuite.scala | 0 .../location/LocationSyntaxSuite.scala | 10 +- .../scala-2/tofu/config/Configurable.scala | 6 +- .../scala-2/tofu/data/instances/order.scala | 6 +- project/Dependencies.scala | 103 +++++++++--------- 94 files changed, 733 insertions(+), 305 deletions(-) rename modules/derivation/src/main/{scala-2 => scala}/tofu/common/derived/display.scala (88%) rename modules/derivation/src/main/{scala-2 => scala}/tofu/data/derived/InitDerivation.scala (64%) rename modules/derivation/src/main/{scala-2 => scala}/tofu/data/derived/Merge.scala (88%) rename modules/derivation/src/main/{scala-2 => scala}/tofu/data/derived/MerkatorFromCats.scala (93%) rename modules/derivation/src/main/{scala-2 => scala}/tofu/data/derived/package.scala (100%) rename modules/derivation/src/main/{scala-2 => scala}/tofu/higherKind/derived/ContextEmbed.scala (100%) rename modules/derivation/src/main/{scala-2 => scala}/tofu/higherKind/derived/derived.scala (100%) rename modules/derivation/src/main/{scala-2 => scala}/tofu/syntax/merge.scala (100%) rename modules/derivation/src/test/{scala-2 => scala}/tofu/common/derived/DisplaySpec.scala (100%) rename modules/derivation/src/test/{scala-2 => scala}/tofu/data/derived/MergeSuite.scala (100%) rename modules/derivation/src/test/{scala-2 => scala}/tofu/higherKind/derived/EmbedSuite.scala (100%) rename modules/derivation/src/test/{scala-2 => scala}/tofu/higherKind/derived/RepresentableKSuite.scala (100%) rename modules/derivation/src/test/{scala-2 => scala}/tofu/higherKind/derived/RepresentableKVarArgSuite.scala (100%) delete mode 100644 modules/kernel/higherKind/src/main/scala-2/tofu/higherKind/Defs.scala rename modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/{loggable.scala => DerivationImpl.scala} (73%) create mode 100644 modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/DerivationImpl.scala create mode 100644 modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala create mode 100644 modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/package.scala rename modules/logging/derivation/src/main/{scala-2 => scala}/tofu/logging/derivation/annotations.scala (100%) create mode 100644 modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala create mode 100644 modules/logging/derivation/src/test/scala-3/DerivedLoggableSuite.scala create mode 100644 modules/logging/structured/src/main/scala-2/tofu/logging/LoggingMidMacroInstances.scala create mode 100644 modules/logging/structured/src/main/scala-2/tofu/logging/LoggingRepresentableKInstances.scala create mode 100644 modules/logging/structured/src/main/scala-2/tofu/logging/ServiceLoggingRepresentableKInstances.scala create mode 100644 modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsRepresentableKInstances.scala rename modules/logging/structured/src/main/scala-2/tofu/logging/location/{Location.scala => LocationMacroInstances.scala} (75%) delete mode 100644 modules/logging/structured/src/main/scala-2/tofu/logging/package.scala create mode 100644 modules/logging/structured/src/main/scala-3/tofu/logging/LoggingMidMacroInstances.scala create mode 100644 modules/logging/structured/src/main/scala-3/tofu/logging/LoggingRepresentableKInstances.scala create mode 100644 modules/logging/structured/src/main/scala-3/tofu/logging/LogsVOps.scala create mode 100644 modules/logging/structured/src/main/scala-3/tofu/logging/ServiceLoggingRepresentableKInstances.scala create mode 100644 modules/logging/structured/src/main/scala-3/tofu/logging/internal/LogsRepresentableKInstances.scala create mode 100644 modules/logging/structured/src/main/scala-3/tofu/logging/location/LocationMacroInstances.scala rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LogAnnotation.scala (96%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LogRenderer.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LogTree.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/Loggable.scala (97%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LoggableContext.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LoggableInstances.scala (97%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LoggedValue.scala (82%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/Logging.scala (88%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LoggingCompanion.scala (73%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/LoggingMid.scala (74%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/Logs.scala (95%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/TethysBuilder.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/atom/AtomLogger.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/bi/LoggingBiCompanion.scala (76%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/bi/LoggingBiMid.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/builder/LoggingBiMidBuilder.scala (84%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/builder/LoggingMidBuilder.scala (79%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/ArgsLoggable.scala (92%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/CachedLogs.scala (96%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/ComposedLoggedValue.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/ContextLoggingImpl.scala (96%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/ContextMarker.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/ContextSyncLoggingImpl.scala (97%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/ContramapLoggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/EmbedLogging.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/EmptyLoggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/FilterLoggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/HiddenLoggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/LoggingImpl.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/LoggingMidFunctions.scala (65%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/NamedLoggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/PlusLoggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/SingletonLoggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/SyncLogging.scala (96%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/UniversalEmbedLogs.scala (99%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/impl/UniversalLogging.scala (97%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/internal/LogsInstances.scala (66%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/logging/internal/LogsInvariantSyntax.scala (75%) create mode 100644 modules/logging/structured/src/main/scala/tofu/logging/location/Location.scala create mode 100644 modules/logging/structured/src/main/scala/tofu/logging/package.scala rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/syntax/location.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/syntax/logRenderer.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/syntax/loggable.scala (100%) rename modules/logging/structured/src/main/{scala-2 => scala}/tofu/syntax/logging.scala (100%) delete mode 100644 modules/logging/structured/src/test/scala-2/tofu/logging/LoggableContextSuite.scala rename modules/logging/structured/src/test/{scala-2 => scala}/tofu/logging/LogTreeSuite.scala (94%) create mode 100644 modules/logging/structured/src/test/scala/tofu/logging/LoggableContextSuite.scala rename modules/logging/structured/src/test/{scala-2 => scala}/tofu/logging/LoggableSuite.scala (100%) rename modules/logging/structured/src/test/{scala-2 => scala}/tofu/logging/LoggingSuite.scala (98%) rename modules/logging/structured/src/test/{scala-2 => scala}/tofu/logging/NamedLoggableCompositionSuite.scala (100%) rename modules/logging/structured/src/test/{scala-2 => scala}/tofu/logging/location/LocationSyntaxSuite.scala (82%) diff --git a/build.sbt b/build.sbt index 158ca8b69..ea7ad1a4b 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,7 @@ import complete.DefaultParsers._ import sbt.librarymanagement.CrossVersion.{binaryScalaVersion, partialVersion} lazy val scala2Versions = List(Version.scala212, Version.scala213) -lazy val scala2And3Versions = scala2Versions ::: List(Version.scala3) +lazy val scala2And3Versions = scala2Versions ++ List(Version.scala3) val scopesDescription = s"Scala version can be: ${scala2And3Versions.mkString}" val testScoped = inputKey[Unit](s"Run tests in the given scope. Usage: testScoped [scala version]. $scopesDescription") @@ -58,12 +58,13 @@ lazy val higherKindCore = projectMatrix defaultSettings, scala3MigratedModuleOptions, name := "tofu-core-higher-kind", + libraryDependencies ++= Seq(catsCore, catsFree, catsTaglessCore), libraryDependencies ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, n)) => - Seq(catsCore, catsFree, catsTaglessMacros) + Seq(catsTaglessMacros) case _ => - Seq(catsCore, catsFree, catsTaglessCore) + Seq.empty } }, ) @@ -128,30 +129,38 @@ lazy val loggingStr = projectMatrix .settings( name := "tofu-logging-structured", defaultSettings, + scala3MigratedModuleOptions, libraryDependencies ++= Seq( catsCore, circeCore, - tethys, - tethysJackson, + // it is impossible to use tethys compiled for scala 3 until https://github.com/tethys-json/tethys/issues/266 is resolved + tethys cross CrossVersion.for3Use2_13, + tethysJackson cross CrossVersion.for3Use2_13, slf4j, alleycats, - scalatest, - derevo, - catsTaglessMacros - ), + catsTaglessCore, + scalatest + ) ) - .jvmPlatform(scala2Versions) + .jvmPlatform(scala2And3Versions) .dependsOn(kernel) lazy val loggingDer = projectMatrix .in(modules / "logging" / "derivation") .settings( defaultSettings, - libraryDependencies ++= Seq(derevo, magnolia, slf4j, glassMacro % Test), + scala3MigratedModuleOptions, + libraryDependencies ++= { + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, _)) => Seq(derevo, magnolia2, slf4j, glassMacro % Test) + case Some((3, _)) => Seq(magnolia3, slf4j) + case _ => Seq.empty + } + }, name := "tofu-logging-derivation" ) - .jvmPlatform(scala2Versions) - .dependsOn(loggingStr, derivation % "compile->test") + .jvmPlatform(scala2And3Versions) + .dependsOn(loggingStr) lazy val loggingLayout = projectMatrix .in(modules / "logging" / "layout") @@ -270,7 +279,7 @@ lazy val config = projectMatrix .in(util / "config") .settings( defaultSettings, - libraryDependencies ++= Seq(typesafeConfig, magnolia, derevo, glassCore), + libraryDependencies ++= Seq(typesafeConfig, magnolia2, derevo, glassCore), name := "tofu-config", ) .jvmPlatform(scala2Versions) @@ -290,7 +299,7 @@ lazy val derivation = projectMatrix .in(modules / "derivation") .settings( defaultSettings, - libraryDependencies ++= Seq(magnolia, derevo, catsTaglessMacros), + libraryDependencies ++= Seq(magnolia2, derevo, catsTaglessMacros), name := "tofu-derivation", ) .jvmPlatform(scala2Versions) @@ -539,8 +548,7 @@ lazy val scala3MigratedModuleOptions = tpolecatScalacOptions ++= Set( ScalacOption("-Ykind-projector:underscores", _ >= ScalaVersion.V3_0_0), ScalacOption("-P:kind-projector:underscore-placeholders", _ < ScalaVersion.V3_0_0), - ScalacOptions.source3, - ScalacOption("-Xmigration", _ < ScalaVersion.V3_0_0) + ScalacOptions.source3 ) ) diff --git a/modules/derivation/src/main/scala-2/tofu/common/derived/display.scala b/modules/derivation/src/main/scala/tofu/common/derived/display.scala similarity index 88% rename from modules/derivation/src/main/scala-2/tofu/common/derived/display.scala rename to modules/derivation/src/main/scala/tofu/common/derived/display.scala index 220b47cef..0194111df 100644 --- a/modules/derivation/src/main/scala-2/tofu/common/derived/display.scala +++ b/modules/derivation/src/main/scala/tofu/common/derived/display.scala @@ -2,7 +2,7 @@ package tofu.common.derived import cats.Eval import derevo.Derivation -import magnolia.{CaseClass, Magnolia, SealedTrait} +import magnolia1.{CaseClass, Magnolia, SealedTrait} import tofu.common.Display /** Derivation of [[Display]] typeclass for case classes and sealed traits @@ -15,7 +15,7 @@ object display extends Derivation[Display] { private type Typeclass[T] = Display[T] - def combine[T](ctx: CaseClass[Typeclass, T]): Display[T] = (cfg: Display.Config, a: T) => { + def join[T](ctx: CaseClass[Typeclass, T]): Display[T] = (cfg: Display.Config, a: T) => { import cfg.{fieldSeparator, indent, brackets, fieldAssign, newline} val nestedIndent = indent + indent @@ -57,8 +57,8 @@ object display extends Derivation[Display] { } .map(s => s :+ brackets.right) } - def dispatch[T](ctx: SealedTrait[Typeclass, T]): Display[T] = (cfg: Display.Config, a: T) => - ctx.dispatch(a)(adtCase => adtCase.typeclass.displayBuild(cfg, adtCase.cast(a))) + def split[T](ctx: SealedTrait[Typeclass, T]): Display[T] = (cfg: Display.Config, a: T) => + ctx.split(a)(adtCase => adtCase.typeclass.displayBuild(cfg, adtCase.cast(a))) def instance[T]: Display[T] = macro Magnolia.gen[T] diff --git a/modules/derivation/src/main/scala-2/tofu/data/derived/InitDerivation.scala b/modules/derivation/src/main/scala/tofu/data/derived/InitDerivation.scala similarity index 64% rename from modules/derivation/src/main/scala-2/tofu/data/derived/InitDerivation.scala rename to modules/derivation/src/main/scala/tofu/data/derived/InitDerivation.scala index 637da156e..d0ef4187e 100644 --- a/modules/derivation/src/main/scala-2/tofu/data/derived/InitDerivation.scala +++ b/modules/derivation/src/main/scala/tofu/data/derived/InitDerivation.scala @@ -1,16 +1,16 @@ package tofu.data.derived import cats.Monad import derevo.Derivation -import magnolia.{CaseClass, Magnolia} -import mercator.Monadic +import magnolia1.{CaseClass, Magnolia} +import magnolia1.Monadic import tofu.Init class InitDerivation[F[_]: Monad] extends Derivation[Init[F, *]] { - private[this] implicit val magnoliaMonad: Monadic[F] = new MerkatorFromCats[F] + private[this] implicit val magnolia1Monad: Monadic[F] = new MerkatorFromCats[F] type Typeclass[A] = Init[F, A] - def combine[X](cc: CaseClass[Typeclass, X]): Init[F, X] = + def join[X](cc: CaseClass[Typeclass, X]): Init[F, X] = new Init[F, X] { def init: F[X] = cc.constructMonadic[F, Any](_.typeclass.init.asInstanceOf[F[Any]]) } diff --git a/modules/derivation/src/main/scala-2/tofu/data/derived/Merge.scala b/modules/derivation/src/main/scala/tofu/data/derived/Merge.scala similarity index 88% rename from modules/derivation/src/main/scala-2/tofu/data/derived/Merge.scala rename to modules/derivation/src/main/scala/tofu/data/derived/Merge.scala index 036b986f2..8913d95af 100644 --- a/modules/derivation/src/main/scala-2/tofu/data/derived/Merge.scala +++ b/modules/derivation/src/main/scala/tofu/data/derived/Merge.scala @@ -3,7 +3,7 @@ package derived import java.time.{Instant, LocalDate, LocalDateTime, ZonedDateTime} import cats.kernel.Semigroup -import magnolia.{CaseClass, Magnolia, SealedTrait} +import magnolia1.{CaseClass, Magnolia, SealedTrait} import derevo.Derivation import tofu.compat.unused @@ -16,11 +16,11 @@ trait Merge[A] { trait MergeInstances1 { type Typeclass[A] = Merge[A] - def combine[T](caseClass: CaseClass[Typeclass, T]): Typeclass[T] = + def join[T](caseClass: CaseClass[Typeclass, T]): Typeclass[T] = (a, b) => caseClass.construct(p => p.typeclass.merge(p.dereference(a), p.dereference(b))) - def dispatch[T](sealedTrait: SealedTrait[Typeclass, T]): Typeclass[T] = - (a, b) => sealedTrait.dispatch(a) { h => if (h.cast.isDefinedAt(b)) h.typeclass.merge(h.cast(a), h.cast(b)) else a } + def split[T](sealedTrait: SealedTrait[Typeclass, T]): Typeclass[T] = + (a, b) => sealedTrait.split(a) { h => if (h.cast.isDefinedAt(b)) h.typeclass.merge(h.cast(a), h.cast(b)) else a } implicit def instance[A]: Merge[A] = macro Magnolia.gen[A] } diff --git a/modules/derivation/src/main/scala-2/tofu/data/derived/MerkatorFromCats.scala b/modules/derivation/src/main/scala/tofu/data/derived/MerkatorFromCats.scala similarity index 93% rename from modules/derivation/src/main/scala-2/tofu/data/derived/MerkatorFromCats.scala rename to modules/derivation/src/main/scala/tofu/data/derived/MerkatorFromCats.scala index 924e5d6ef..f06dee4a1 100644 --- a/modules/derivation/src/main/scala-2/tofu/data/derived/MerkatorFromCats.scala +++ b/modules/derivation/src/main/scala/tofu/data/derived/MerkatorFromCats.scala @@ -1,6 +1,6 @@ package tofu.data.derived import cats.Monad -import mercator.Monadic +import magnolia1.Monadic class MerkatorFromCats[F[_]](implicit F: Monad[F]) extends Monadic[F] { def point[A](value: A): F[A] = F.pure(value) diff --git a/modules/derivation/src/main/scala-2/tofu/data/derived/package.scala b/modules/derivation/src/main/scala/tofu/data/derived/package.scala similarity index 100% rename from modules/derivation/src/main/scala-2/tofu/data/derived/package.scala rename to modules/derivation/src/main/scala/tofu/data/derived/package.scala diff --git a/modules/derivation/src/main/scala-2/tofu/higherKind/derived/ContextEmbed.scala b/modules/derivation/src/main/scala/tofu/higherKind/derived/ContextEmbed.scala similarity index 100% rename from modules/derivation/src/main/scala-2/tofu/higherKind/derived/ContextEmbed.scala rename to modules/derivation/src/main/scala/tofu/higherKind/derived/ContextEmbed.scala diff --git a/modules/derivation/src/main/scala-2/tofu/higherKind/derived/derived.scala b/modules/derivation/src/main/scala/tofu/higherKind/derived/derived.scala similarity index 100% rename from modules/derivation/src/main/scala-2/tofu/higherKind/derived/derived.scala rename to modules/derivation/src/main/scala/tofu/higherKind/derived/derived.scala diff --git a/modules/derivation/src/main/scala-2/tofu/syntax/merge.scala b/modules/derivation/src/main/scala/tofu/syntax/merge.scala similarity index 100% rename from modules/derivation/src/main/scala-2/tofu/syntax/merge.scala rename to modules/derivation/src/main/scala/tofu/syntax/merge.scala diff --git a/modules/derivation/src/test/scala-2/tofu/common/derived/DisplaySpec.scala b/modules/derivation/src/test/scala/tofu/common/derived/DisplaySpec.scala similarity index 100% rename from modules/derivation/src/test/scala-2/tofu/common/derived/DisplaySpec.scala rename to modules/derivation/src/test/scala/tofu/common/derived/DisplaySpec.scala diff --git a/modules/derivation/src/test/scala-2/tofu/data/derived/MergeSuite.scala b/modules/derivation/src/test/scala/tofu/data/derived/MergeSuite.scala similarity index 100% rename from modules/derivation/src/test/scala-2/tofu/data/derived/MergeSuite.scala rename to modules/derivation/src/test/scala/tofu/data/derived/MergeSuite.scala diff --git a/modules/derivation/src/test/scala-2/tofu/higherKind/derived/EmbedSuite.scala b/modules/derivation/src/test/scala/tofu/higherKind/derived/EmbedSuite.scala similarity index 100% rename from modules/derivation/src/test/scala-2/tofu/higherKind/derived/EmbedSuite.scala rename to modules/derivation/src/test/scala/tofu/higherKind/derived/EmbedSuite.scala diff --git a/modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKSuite.scala b/modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKSuite.scala similarity index 100% rename from modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKSuite.scala rename to modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKSuite.scala diff --git a/modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKVarArgSuite.scala b/modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKVarArgSuite.scala similarity index 100% rename from modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKVarArgSuite.scala rename to modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKVarArgSuite.scala diff --git a/modules/kernel/higherKind/src/main/scala-2/tofu/higherKind/Defs.scala b/modules/kernel/higherKind/src/main/scala-2/tofu/higherKind/Defs.scala deleted file mode 100644 index f8b8010f9..000000000 --- a/modules/kernel/higherKind/src/main/scala-2/tofu/higherKind/Defs.scala +++ /dev/null @@ -1,5 +0,0 @@ -package tofu.higherKind - -object Defs { - type HKAny[A] = Any -} diff --git a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Function2K.scala b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Function2K.scala index f3e58a213..9c358233b 100644 --- a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Function2K.scala +++ b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Function2K.scala @@ -11,8 +11,6 @@ trait Function2K[F[_], G[_], H[_]] { } object Function2K { - type HKAny[A] = Any - private[this] val representableAny = new Function2KRepresentable[HKAny, HKAny] implicit def representableK[F[_], G[_]]: RepresentableK[({ type L[x[_]] = Function2K[F, G, x] })#L] = diff --git a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/package.scala b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/package.scala index 3ff53bd57..11bd1dbdf 100644 --- a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/package.scala +++ b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/package.scala @@ -4,4 +4,6 @@ package object higherKind { type Pre[F[_], A] = Pre.T[F, A] type UnitK[A] = Unit + + type HKAny[_] = Any } diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/loggable.scala b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/DerivationImpl.scala similarity index 73% rename from modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/loggable.scala rename to modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/DerivationImpl.scala index db3d4c6e8..315d2dbd1 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/loggable.scala +++ b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/DerivationImpl.scala @@ -2,17 +2,17 @@ package tofu.logging package derivation import cats.Show -import magnolia.{CaseClass, Magnolia, SealedTrait} +import magnolia1.{CaseClass, Magnolia, SealedTrait} import derevo.Derivation import derevo.NewTypeDerivation -object loggable extends Derivation[Loggable] with NewTypeDerivation[Loggable] { +trait DerivationImpl extends Derivation[Loggable] with NewTypeDerivation[Loggable] { type Typeclass[A] = Loggable[A] def byShow[T: Show](name: String): Loggable[T] = Loggable.stringValue.contramap(Show[T].show).named(name) - def combine[T](ctx: CaseClass[Typeclass, T]): Loggable[T] = new DictLoggable[T] { + def join[T](ctx: CaseClass[Typeclass, T]): Loggable[T] = new DictLoggable[T] { private[this] val doNotShow = ctx.annotations.contains(hidden()) override val typeName: String = calcTypeName(ctx.typeName) @@ -37,24 +37,24 @@ object loggable extends Derivation[Loggable] with NewTypeDerivation[Loggable] { def logShow(value: T): String = if (doNotShow) "" - else join(ctx.typeName.short, masking.params[Typeclass, T](value, ctx.parameters)(_.logShow)) + else strJoin(ctx.typeName.short, masking.params[Typeclass, T](value, ctx.parameters)(_.logShow)) } - def dispatch[T](ctx: SealedTrait[Typeclass, T]): Loggable[T] = new Typeclass[T] { + def split[T](ctx: SealedTrait[Typeclass, T]): Loggable[T] = new Typeclass[T] { override val typeName: String = calcTypeName(ctx.typeName) override val shortName: String = ctx.typeName.short def fields[I, V, R, M](a: T, input: I)(implicit receiver: LogRenderer[I, V, R, M]): R = - ctx.dispatch(a)(sub => sub.typeclass.fields(sub.cast(a), input)) + ctx.split(a)(sub => sub.typeclass.fields(sub.cast(a), input)) def putValue[I, V, R, M](a: T, v: V)(implicit r: LogRenderer[I, V, R, M]): M = - ctx.dispatch(a)(sub => sub.typeclass.putValue(sub.cast(a), v)) + ctx.split(a)(sub => sub.typeclass.putValue(sub.cast(a), v)) def logShow(a: T): String = - ctx.dispatch(a)(sub => sub.typeclass.logShow(sub.cast(a))) + ctx.split(a)(sub => sub.typeclass.logShow(sub.cast(a))) override def putField[I, V, R, M](a: T, name: String, input: I)(implicit receiver: LogRenderer[I, V, R, M]): R = - ctx.dispatch(a)(sub => sub.typeclass.putField(sub.cast(a), name, input)) + ctx.split(a)(sub => sub.typeclass.putField(sub.cast(a), name, input)) } def instance[A]: Loggable[A] = macro Magnolia.gen[A] diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/masking.scala b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/masking.scala index 8c99597db..70cae2e00 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/masking.scala +++ b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/masking.scala @@ -3,7 +3,7 @@ package tofu.logging.derivation import scala.annotation.tailrec import scala.util.matching.Regex -import magnolia.Param +import magnolia1.Param sealed trait MaskMode object MaskMode { diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/package.scala b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/package.scala index 173afb23d..de2fcaf45 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/package.scala +++ b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/package.scala @@ -1,10 +1,13 @@ package tofu.logging -import magnolia.TypeName +import magnolia1.TypeName import scala.collection.compat._ package object derivation { - private[derivation] def join(typeName: String, strings: IterableOnce[String]): String = + + type MagnoliaParam[TC[_], T] = magnolia1.Param[TC, T] + + private[derivation] def strJoin(typeName: String, strings: IterableOnce[String]): String = if (strings.iterator.isEmpty) typeName else strings.iterator.mkString(s"$typeName{", ",", "}") private[derivation] def calcTypeName(typeName: TypeName, seen: Set[TypeName] = Set()): String = diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/show.scala b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/show.scala index 8655de572..e5b3ad97d 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/show.scala +++ b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/show.scala @@ -2,7 +2,7 @@ package tofu.logging.derivation import cats.Show -import magnolia.{CaseClass, Magnolia, SealedTrait} +import magnolia1.{CaseClass, Magnolia, SealedTrait} import derevo.Derivation import derevo.NewTypeDerivation @@ -17,15 +17,15 @@ object show extends Derivation[Show] with NewTypeDerivation[Show] { /** creates a new [[Show]] instance by labelling and joining (with `mkString`) the result of showing each parameter, * and prefixing it with the class name */ - def combine[T](ctx: CaseClass[Typeclass, T]): Show[T] = value => + def join[T](ctx: CaseClass[Typeclass, T]): Show[T] = value => if (ctx.isValueClass) { val param = ctx.parameters.head param.typeclass.show(param.dereference(value)) - } else join(ctx.typeName.short, masking.params[Typeclass, T](value, ctx.parameters)(_.show)) + } else strJoin(ctx.typeName.short, masking.params[Typeclass, T](value, ctx.parameters)(_.show)) /** choose which typeclass to use based on the subtype of the sealed trait */ - def dispatch[T](ctx: SealedTrait[Typeclass, T]): Show[T] = value => - ctx.dispatch(value)(sub => sub.typeclass.show(sub.cast(value))) + def split[T](ctx: SealedTrait[Typeclass, T]): Show[T] = value => + ctx.split(value)(sub => sub.typeclass.show(sub.cast(value))) def instance[T]: Show[T] = macro Magnolia.gen[T] diff --git a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/DerivationImpl.scala b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/DerivationImpl.scala new file mode 100644 index 000000000..cea547011 --- /dev/null +++ b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/DerivationImpl.scala @@ -0,0 +1,57 @@ +package tofu.logging +package derivation + +import cats.Show +import magnolia1.* + +trait DerivationImpl extends AutoDerivation[Loggable] { + + def byShow[T: Show](name: String): Loggable[T] = + Loggable.stringValue.contramap(Show[T].show).named(name) + + def join[T](ctx: CaseClass[Typeclass, T]): Loggable[T] = new DictLoggable[T] { + private[this] val doNotShow = ctx.annotations.contains(hidden()) + + override val typeName: String = calcTypeName(ctx.typeInfo) + override val shortName: String = ctx.typeInfo.short + + def fields[I, V, R, M](a: T, input: I)(implicit receiver: LogRenderer[I, V, R, M]): R = + ctx.parameters.iterator + .filter(!_.annotations.contains(hidden())) + .foldLeft(receiver.noop(input)) { (acc, param) => + import param._ + + val value = deref(a) + typeclass match { + case _ if annotations.contains(unembed()) => + receiver.combine(acc, typeclass.fields(value, input)) + case _ => + annotations.collectFirst { case masked(mode) => + receiver.combine(acc, typeclass.putMaskedField(value, label, input)(masking.string(_, mode))) + }.getOrElse(receiver.combine(acc, typeclass.putField(value, label, input))) + } + } + + def logShow(value: T): String = + if (doNotShow) "" + else strJoin(ctx.typeInfo.short, masking.params[Typeclass, T](value, ctx.parameters)(_.logShow)) + } + + def split[T](ctx: SealedTrait[Typeclass, T]): Loggable[T] = new Typeclass[T] { + override val typeName: String = calcTypeName(ctx.typeInfo) + override val shortName: String = ctx.typeInfo.short + + def fields[I, V, R, M](a: T, input: I)(implicit receiver: LogRenderer[I, V, R, M]): R = + ctx.choose(a)(sub => sub.typeclass.fields(sub.cast(a), input)) + + def putValue[I, V, R, M](a: T, v: V)(implicit r: LogRenderer[I, V, R, M]): M = + ctx.choose(a)(sub => sub.typeclass.putValue(sub.cast(a), v)) + + def logShow(a: T): String = + ctx.choose(a)(sub => sub.typeclass.logShow(sub.cast(a))) + + override def putField[I, V, R, M](a: T, name: String, input: I)(implicit receiver: LogRenderer[I, V, R, M]): R = + ctx.choose(a)(sub => sub.typeclass.putField(sub.cast(a), name, input)) + } + +} diff --git a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala new file mode 100644 index 000000000..2215e490f --- /dev/null +++ b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala @@ -0,0 +1,94 @@ +package tofu.logging.derivation + +import scala.annotation.tailrec +import scala.util.matching.Regex + +import magnolia1.CaseClass.Param + +sealed trait MaskMode +object MaskMode { + + /** Replaces each digit with "#" and each letter with "*". Other symbols are not changed */ + case object Full extends MaskMode + + /** Replaces value with "..." */ + case object Erase extends MaskMode + + /** Same as [[Full]] but for some part of value */ + case class ForLength(offset: Int, maxLength: Int = -1) extends MaskMode { + def this(length: Int) = this(0, length) + } + case class Regexp(pattern: Regex) extends MaskMode +} + +object masking { + private val SomeRe = "(?<=^Some(\\{value=|\\())(.+)(?=(\\}|\\))$)".r + + private[derivation] def string(shown: String, mode: MaskMode) = { + @tailrec + def loop(arr: Array[Char], cur: Int, left: Int): String = { + if (left == 0 || cur == arr.length) new String(arr) + else { + val char = arr(cur) + if (char.isDigit) arr(cur) = '#' + else if (char.isLetter) arr(cur) = '*' + + loop(arr, cur + 1, left - 1) + } + } + + mode match { + case MaskMode.Erase => + "..." + case MaskMode.Full => + loop(shown.toCharArray, 0, shown.length) + case MaskMode.Regexp(pattern) => + pattern + .findFirstMatchIn(shown) + .collect { + case m if m.groupCount == 1 => + val start = m.start(1) + val end = m.end(1) + + loop(shown.toCharArray, start, end - start) + } + .getOrElse(shown) + case MaskMode.ForLength(offset, maxLength) => + loop(shown.toCharArray, shown.length min (offset max 0), if (maxLength == -1) shown.length else maxLength) + } + } + + private[derivation] def field[T](field: T, shown: String, mode: MaskMode) = field match { + case None => shown + case Some(_) => SomeRe.replaceSomeIn(shown, m => Some(string(m.toString, mode))) + case _ => string(shown, mode) + } + + private[derivation] def params[TypeClass[_], Type]( + tpe: Type, + params: Seq[Param[TypeClass, Type]] + )(fn: TypeClass[Any] => Any => String) = + params.iterator + .filterNot(_.annotations.contains(hidden())) + .flatMap { param => + import param._ + + val value: PType = deref(tpe) + if (value == None && param.annotations.contains(ignoreOpt())) + None + else { + val shown = fn(typeclass.asInstanceOf[TypeClass[Any]])(value) + + val repr = annotations.collectFirst { case masked(mode) => field(value, shown, mode) } + .getOrElse(shown) + + Some(s"$label=$repr") + } + } + + implicit final class Ops(private val value: String) extends AnyVal { + def mask: String = mask(MaskMode.Full) + + def mask(mode: MaskMode): String = string(value, mode) + } +} diff --git a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/package.scala b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/package.scala new file mode 100644 index 000000000..cc888365e --- /dev/null +++ b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/package.scala @@ -0,0 +1,23 @@ +package tofu.logging + +import magnolia1.TypeInfo +import scala.collection.compat._ +import scala.deriving.Mirror + +package object derivation { + + extension (x: Loggable.type) inline def derived[A](using Mirror.Of[A]): Loggable[A] = loggable.derived[A] + + private[derivation] def strJoin(typeName: String, strings: IterableOnce[String]): String = + if (strings.iterator.isEmpty) typeName else strings.iterator.mkString(s"$typeName{", ",", "}") + + private[derivation] def calcTypeName(typeName: TypeInfo, seen: Set[TypeInfo] = Set()): String = + if (seen(typeName)) "#" + else { + val args = typeName.typeParams + val name = typeName.full + + if (args.isEmpty) name + else args.iterator.map(calcTypeName(_, seen + typeName)).mkString(name + "[", ",", "]") + } +} diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/annotations.scala b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/annotations.scala similarity index 100% rename from modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/annotations.scala rename to modules/logging/derivation/src/main/scala/tofu/logging/derivation/annotations.scala diff --git a/modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala new file mode 100644 index 000000000..af709f974 --- /dev/null +++ b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala @@ -0,0 +1,3 @@ +package tofu.logging.derivation + +object loggable extends DerivationImpl diff --git a/modules/logging/derivation/src/test/scala-2/tofu/logging/derivation/LoggingMidSuite.scala b/modules/logging/derivation/src/test/scala-2/tofu/logging/derivation/LoggingMidSuite.scala index f7c272b61..de0cf5390 100644 --- a/modules/logging/derivation/src/test/scala-2/tofu/logging/derivation/LoggingMidSuite.scala +++ b/modules/logging/derivation/src/test/scala-2/tofu/logging/derivation/LoggingMidSuite.scala @@ -5,12 +5,14 @@ import derevo.derive import org.scalatest.funsuite.AnyFunSuite import org.slf4j.helpers.MessageFormatter import tofu.data._ -import tofu.higherKind.derived.representableK import glass.macros.Optics +import tofu.higherKind.RepK +import tofu.higherKind.RepresentableK +import cats.~> import LoggingMidSuite._ -@derive(representableK, loggingMidTry) +@derive(loggingMidTry) trait Greeter[F[_]] { def setName(name: String): F[Unit] def hello: F[String] @@ -18,6 +20,14 @@ trait Greeter[F[_]] { object Greeter extends LoggingCompanion[Greeter] { import LoggingMidSuite._ + + implicit val repK: RepresentableK[Greeter] = + new RepresentableK[Greeter] { + def tabulate[F[_]](hom: RepK[Greeter, _] ~> F): Greeter[F] = new Greeter[F] { + def setName(name: String): F[Unit] = hom(RepK[Greeter](_.setName(name))) + def hello: F[String] = hom(RepK[Greeter](_.hello)) + } + } implicit object Instance extends Greeter[Eff] { def setName(name: String): Eff[Unit] = CalcM.set(Some(name)).focus(State.name).void @@ -46,7 +56,7 @@ object LoggingMidSuite { } } - implicit val logs: Logs.Universal[Eff] = logging + implicit val logs: Logs.Universal[Eff] = logging(_) } class LoggingMidSuite extends AnyFunSuite { diff --git a/modules/logging/derivation/src/test/scala-3/DerivedLoggableSuite.scala b/modules/logging/derivation/src/test/scala-3/DerivedLoggableSuite.scala new file mode 100644 index 000000000..09bb6a386 --- /dev/null +++ b/modules/logging/derivation/src/test/scala-3/DerivedLoggableSuite.scala @@ -0,0 +1,92 @@ +package tofu.logging +package derivation + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class DerivedLoggableSuite extends AnyFlatSpec with Matchers { + + import DerivedLoggableSuite._ + + val foo = Foo("zaz", Some(1)) + + def json[A: Loggable](a: A) = TethysBuilder(a) + + "Foo logging" should "not rendered None" in { + json(foo.copy(kek = None)) shouldBe """{"lol":"zaz"}""" + } + it should "not rendered Some flat" in { + json(foo) shouldBe """{"lol":"zaz","kek":1}""" + } + + "Bar logging" should "hide fields" in { + json(Bar(foo1 = Some(foo))) shouldBe "{}" + } + + it should "unembed fields" in { + json(Bar(foo2 = Some(foo))) shouldBe """{"lol":"zaz","kek":1}""" + } + + it should "embed fields" in { + json(Bar(foo3 = Some(foo))) shouldBe """{"foo3":{"lol":"zaz","kek":1}}""" + } + + "Baz logging" should "respect object collections" in { + json(Baz(foos = List(foo, foo))) shouldBe """{"foos":[{"lol":"zaz","kek":1},{"lol":"zaz","kek":1}],"ys":[]}""" + } + + it should "respect primitive collections" in { + json(Baz(ys = Vector(1, 2, 3, 4))) shouldBe """{"foos":[],"ys":[1,2,3,4]}""" + } + + it should "respect complex primitive collections" in { + json( + Baz(zs = Some(List(List("one", "two"), List("three")))) + ) shouldBe """{"foos":[],"ys":[],"zs":[["one","two"],["three"]]}""" + } + + it should "respect masking" in { + json( + Jak("one", 4567, 3.123456, List(1.234, 5.678)) + ) shouldBe """{"one":"...","two":"4###","three":"3.######","four":["1.###","5.###"]}""" + } + + "MaskedBaz" should "emit Some" in { + json( + MaskedBaz(Some("auf")) + ) shouldBe """{"kek":"***"}""" + } + + it should "not emit None" in { + json( + MaskedBaz(None) + ) shouldBe """{}""" + } + + it should "not show for None with ignoreOpt" in { + Loggable[MaskedBaz].logShow(MaskedBaz(None)) shouldBe "MaskedBaz{kek=}" + } + +} + +object DerivedLoggableSuite { + final case class Foo(lol: String, kek: Option[Long]) derives Loggable + + final case class Bar( + @hidden foo1: Option[Foo] = None, + @unembed foo2: Option[Foo] = None, + foo3: Option[Foo] = None + ) derives Loggable + + final case class Jak( + @masked(MaskMode.Erase) one: String, + @masked(MaskMode.ForLength(1)) two: Long, + @masked(MaskMode.Regexp("\\d*\\.(\\d*)".r)) three: Double, + @masked(MaskMode.Regexp("-?\\d*\\.(\\d*)".r)) four: List[Double], + ) derives Loggable + + final case class Baz(foos: List[Foo] = Nil, ys: Vector[Int] = Vector(), zs: Option[List[List[String]]] = None) + derives Loggable + + final case class MaskedBaz(@masked kek: Option[String], @ignoreOpt a: Option[String] = None) derives Loggable +} diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingMidMacroInstances.scala b/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingMidMacroInstances.scala new file mode 100644 index 000000000..5201fc992 --- /dev/null +++ b/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingMidMacroInstances.scala @@ -0,0 +1,7 @@ +package tofu.logging + +import tofu.higherKind.derived.HigherKindedMacros + +trait LoggingMidMacroInstances { + def instance[U[_[_]]]: U[LoggingMid] = macro HigherKindedMacros.factorizeThis[U] +} diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingRepresentableKInstances.scala b/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingRepresentableKInstances.scala new file mode 100644 index 000000000..3dac1e483 --- /dev/null +++ b/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingRepresentableKInstances.scala @@ -0,0 +1,8 @@ +package tofu.logging + +import tofu.higherKind.RepresentableK +import tofu.higherKind + +trait LoggingRepresentableKInstances { + implicit val loggingRepresentable: RepresentableK[Logging] = higherKind.derived.genRepresentableK[Logging] +} diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/ServiceLoggingRepresentableKInstances.scala b/modules/logging/structured/src/main/scala-2/tofu/logging/ServiceLoggingRepresentableKInstances.scala new file mode 100644 index 000000000..7ff07154b --- /dev/null +++ b/modules/logging/structured/src/main/scala-2/tofu/logging/ServiceLoggingRepresentableKInstances.scala @@ -0,0 +1,14 @@ +package tofu +package logging + +import tofu.higherKind.RepresentableK + +trait ServiceLoggingRepresentableKInstances { + + private[this] val representableAny: RepresentableK[({ type L[x[_]] = ServiceLogging[x, Any] })#L] = + higherKind.derived.genRepresentableK[({ type L[x[_]] = ServiceLogging[x, Any] })#L] + + final implicit def serviceLoggingRepresentable[Svc]: RepresentableK[({ type L[x[_]] = ServiceLogging[x, Svc] })#L] = + representableAny.asInstanceOf[RepresentableK[({ type L[x[_]] = ServiceLogging[x, Svc] })#L]] + +} diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsRepresentableKInstances.scala b/modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsRepresentableKInstances.scala new file mode 100644 index 000000000..8072b962a --- /dev/null +++ b/modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsRepresentableKInstances.scala @@ -0,0 +1,18 @@ +package tofu.logging.internal + +import tofu.higherKind +import tofu.higherKind.RepresentableK +import tofu.logging.Logs +import cats.Id + +trait LogsRepresentableKInstances { + private[this] val logs1RepresentableAny: RepresentableK[({ type L[x[_]] = Logs[x, Any] })#L] = + higherKind.derived.genRepresentableK[({ type L[x[_]] = Logs[x, Any] })#L] + + implicit def logs1Representable[Y[_]]: RepresentableK[({ type L[x[_]] = Logs[x, Y] })#L] = + logs1RepresentableAny.asInstanceOf[RepresentableK[({ type L[x[_]] = Logs[x, Y] })#L]] + + implicit val logs2UniversalRepresentable: RepresentableK[({ type L[x[_]] = Logs[Id, x] })#L] = + higherKind.derived.genRepresentableK[({ type L[x[_]] = Logs[Id, x] })#L] + +} diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/location/Location.scala b/modules/logging/structured/src/main/scala-2/tofu/logging/location/LocationMacroInstances.scala similarity index 75% rename from modules/logging/structured/src/main/scala-2/tofu/logging/location/Location.scala rename to modules/logging/structured/src/main/scala-2/tofu/logging/location/LocationMacroInstances.scala index f1dfd061e..2d3c42490 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/location/Location.scala +++ b/modules/logging/structured/src/main/scala-2/tofu/logging/location/LocationMacroInstances.scala @@ -1,23 +1,13 @@ package tofu.logging.location -import tofu.logging.Loggable - import scala.annotation.tailrec import scala.collection.mutable import scala.reflect.macros.blackbox -import scala.annotation.nowarn - -case class Location(file: String, line: Int, applicationPoint: String) - -object Location { - implicit val loggable: Loggable[Location] = Loggable[String].contramap { case Location(file, line, point) => - s"$point@($file:$line)" - } +trait LocationMacroInstances { implicit def location: Location = macro LocationMacro.getEnclosingPosition } -@nowarn("cat=lint-infer-any") object LocationMacro { /** Based on Izumi Logstage CodePosition */ @@ -56,14 +46,14 @@ object LocationMacro { val st = mutable.ArrayBuffer[c.Symbol]() rec(c.internal.enclosingOwner, st) - st.tail.map { - case s if s.isPackage => s.name - case s if goodSymbol(s) => s.name + st.tail.flatMap { + case s if s.isPackage => Some(s.name) + case s if goodSymbol(s) => Some(s.name) case s => if (s.isClass) { - s.asClass.baseClasses.find(goodSymbol).map(_.name).getOrElse(s.pos.line) + s.asClass.baseClasses.find(goodSymbol).map(_.name) } else { - s.pos.line + None } } .map(_.toString.trim) diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/package.scala b/modules/logging/structured/src/main/scala-2/tofu/logging/package.scala deleted file mode 100644 index 221481817..000000000 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package tofu - -package object logging { - type ModuleLog[F[_], U[_[_]]] = ServiceLogging[F, U[Any]] -} diff --git a/modules/logging/structured/src/main/scala-3/tofu/logging/LoggingMidMacroInstances.scala b/modules/logging/structured/src/main/scala-3/tofu/logging/LoggingMidMacroInstances.scala new file mode 100644 index 000000000..28b745293 --- /dev/null +++ b/modules/logging/structured/src/main/scala-3/tofu/logging/LoggingMidMacroInstances.scala @@ -0,0 +1,4 @@ +package tofu.logging + +// TODO: use higherKind.factorizeThis macro when it is ready +trait LoggingMidMacroInstances diff --git a/modules/logging/structured/src/main/scala-3/tofu/logging/LoggingRepresentableKInstances.scala b/modules/logging/structured/src/main/scala-3/tofu/logging/LoggingRepresentableKInstances.scala new file mode 100644 index 000000000..d562b56f9 --- /dev/null +++ b/modules/logging/structured/src/main/scala-3/tofu/logging/LoggingRepresentableKInstances.scala @@ -0,0 +1,16 @@ +package tofu.logging + +import cats.~> +import tofu.higherKind.{RepresentableK, RepK} +import tofu.logging.Logging.Level + +trait LoggingRepresentableKInstances { + + // TODO: use higherKind.derived macro when it is ready + given loggingRepresentable: RepresentableK[Logging] = new RepresentableK[Logging] { + def tabulate[F[_]](hom: RepK[Logging, _] ~> F): Logging[F] = new Logging[F] { + def write(level: Level, message: String, values: LoggedValue*): F[Unit] = + hom(RepK[Logging](_.write(level, message, values: _*))) + } + } +} diff --git a/modules/logging/structured/src/main/scala-3/tofu/logging/LogsVOps.scala b/modules/logging/structured/src/main/scala-3/tofu/logging/LogsVOps.scala new file mode 100644 index 000000000..18ec1210f --- /dev/null +++ b/modules/logging/structured/src/main/scala-3/tofu/logging/LogsVOps.scala @@ -0,0 +1,9 @@ +package tofu.logging + +trait LogsVOps[+I[_], F[_]] { self: Logs[I, F] => + final def named[name <: String with Singleton](implicit + name: ValueOf[name] + ): I[ServiceLogging[F, name]] = + byName(name.value).asInstanceOf[I[ServiceLogging[F, name]]] + +} diff --git a/modules/logging/structured/src/main/scala-3/tofu/logging/ServiceLoggingRepresentableKInstances.scala b/modules/logging/structured/src/main/scala-3/tofu/logging/ServiceLoggingRepresentableKInstances.scala new file mode 100644 index 000000000..a554eda75 --- /dev/null +++ b/modules/logging/structured/src/main/scala-3/tofu/logging/ServiceLoggingRepresentableKInstances.scala @@ -0,0 +1,4 @@ +package tofu.logging + +// TODO: use higherKind.derived macro when it is ready +trait ServiceLoggingRepresentableKInstances diff --git a/modules/logging/structured/src/main/scala-3/tofu/logging/internal/LogsRepresentableKInstances.scala b/modules/logging/structured/src/main/scala-3/tofu/logging/internal/LogsRepresentableKInstances.scala new file mode 100644 index 000000000..de7318b92 --- /dev/null +++ b/modules/logging/structured/src/main/scala-3/tofu/logging/internal/LogsRepresentableKInstances.scala @@ -0,0 +1,5 @@ +package tofu.logging.internal + +trait LogsRepresentableKInstances { + // TODO +} diff --git a/modules/logging/structured/src/main/scala-3/tofu/logging/location/LocationMacroInstances.scala b/modules/logging/structured/src/main/scala-3/tofu/logging/location/LocationMacroInstances.scala new file mode 100644 index 000000000..2ad029438 --- /dev/null +++ b/modules/logging/structured/src/main/scala-3/tofu/logging/location/LocationMacroInstances.scala @@ -0,0 +1,58 @@ +package tofu.logging.location + +import scala.annotation.tailrec +import scala.collection.mutable +import scala.quoted.{Quotes, Expr} + +trait LocationMacroInstances: + inline given location: Location = ${ LocationMacro.getEnclosingPosition } + +object LocationMacro: + + /** Based on Izumi Logstage CodePosition */ + def getEnclosingPosition(using quotes: Quotes): Expr[Location] = { + import quotes.reflect.Position + val file = Expr(Position.ofMacroExpansion.sourceFile.name) + val line = Expr(Position.ofMacroExpansion.startLine + 1) + val applicationPoint = getApplicationPointId() + '{ new Location($file, $line, $applicationPoint) } + } + + private def ownershipChain()(using quotes: Quotes): Seq[quotes.reflect.Symbol] = { + import quotes.reflect.* + + @tailrec + def extractOwnershipChain(s: Symbol, st: mutable.ArrayBuffer[Symbol]): Unit = { + st.prepend(s) + s.maybeOwner match { + case n if n.isNoSymbol => + case o => + extractOwnershipChain(o, st) + + } + } + + val st = mutable.ArrayBuffer[Symbol]() + extractOwnershipChain(Symbol.spliceOwner, st) + st.toSeq + } + + private def getApplicationPointId()(using quotes: Quotes): Expr[String] = { + val st = ownershipChain() + + val applicationId = st.tail.flatMap { + case s if s.isPackageDef => Some(s.name) + case s if s.isValDef => None + case s if goodSymbol(s) => Some(s.name) + case _ => None + } + .map(_.trim) + .mkString(".") + + Expr(applicationId) + } + + private def goodSymbol(using qctx: Quotes)(s: qctx.reflect.Symbol): Boolean = { + val name = s.name + !name.startsWith("$") && !name.startsWith("<") + } diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LogAnnotation.scala b/modules/logging/structured/src/main/scala/tofu/logging/LogAnnotation.scala similarity index 96% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LogAnnotation.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LogAnnotation.scala index 60089db10..657a91e0d 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/LogAnnotation.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LogAnnotation.scala @@ -23,7 +23,7 @@ class LogAnnotation[A](val name: String, valueLoggable: Loggable[A]) { override def hashCode: Int = name.hashCode override def equals(other: Any): Boolean = other match { - case other: LogAnnotation[_] => name == other.name + case other: LogAnnotation[?] => name == other.name case _ => false } diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LogRenderer.scala b/modules/logging/structured/src/main/scala/tofu/logging/LogRenderer.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LogRenderer.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LogRenderer.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LogTree.scala b/modules/logging/structured/src/main/scala/tofu/logging/LogTree.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LogTree.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LogTree.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/Loggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/Loggable.scala similarity index 97% rename from modules/logging/structured/src/main/scala-2/tofu/logging/Loggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/Loggable.scala index 408b646ed..73568cf71 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/Loggable.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/Loggable.scala @@ -9,7 +9,7 @@ import tofu.logging.impl._ import tofu.syntax.logRenderer._ import scala.annotation.unused -import scala.{PartialFunction => PF, specialized => sp} +import scala.{PartialFunction => PF} /** Typeclass for adding custom log values to message */ @@ -39,7 +39,7 @@ trait Loggable[A] extends Loggable.Base[A] { */ def singleton(name: String): Loggable[A] = new SingletonLoggable[A](name, this) - def showInstance: Show[A] = logShow + def showInstance: Show[A] = (a: A) => logShow(a) def narrow[B <: A]: Loggable[B] = this.asInstanceOf[Loggable[B]] @@ -105,7 +105,7 @@ object Loggable extends LoggableInstances with DataComp[Loggable] { * new Logged Value */ def loggedValue(a: A): LoggedValue = new LoggedValue { - override def logFields[I, V, @sp(Unit) R, @sp M](i: I)(implicit r: LogRenderer[I, V, R, M]): R = + override def logFields[I, V, @specialized(Unit) R, @specialized M](i: I)(implicit r: LogRenderer[I, V, R, M]): R = fields[I, V, R, M](a, i) override def putValue[I, V, R, S](v: V)(implicit r: LogRenderer[I, V, R, S]): S = self.putValue(a, v) diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggableContext.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggableContext.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LoggableContext.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LoggableContext.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggableInstances.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala similarity index 97% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LoggableInstances.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala index 86b05953e..69dd4eeb4 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggableInstances.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala @@ -6,7 +6,6 @@ import java.util.UUID import scala.collection.immutable.SortedSet import scala.collection.{immutable, mutable} import scala.concurrent.duration.FiniteDuration -import scala.{specialized => sp} import alleycats.std.iterable._ import alleycats.std.set._ @@ -184,10 +183,11 @@ class LoggableInstances { case Some(a) => loggable.putValue(a, v) } - def fields[I, V, R, @sp(Unit) M](oa: Option[T], i: I)(implicit receiver: LogRenderer[I, V, R, M]): R = oa match { - case None => i.noop - case Some(a) => loggable.fields(a, i) - } + def fields[I, V, R, @specialized(Unit) M](oa: Option[T], i: I)(implicit receiver: LogRenderer[I, V, R, M]): R = + oa match { + case None => i.noop + case Some(a) => loggable.fields(a, i) + } override def putField[I, V, R, M](oa: Option[T], name: String, input: I)(implicit receiver: LogRenderer[I, V, R, M] diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggedValue.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggedValue.scala similarity index 82% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LoggedValue.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LoggedValue.scala index 568fea62f..b3f1fdfcc 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggedValue.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LoggedValue.scala @@ -3,13 +3,11 @@ package tofu.logging import cats.kernel.Semigroup import tofu.logging.impl.ComposedLoggedValue -import scala.{specialized => sp} - trait LoggedValue { def typeName: String = "" def shortName: String = "" - def logFields[I, V, @sp(Unit) R, @sp M](input: I)(implicit r: LogRenderer[I, V, R, M]): R + def logFields[I, V, @specialized(Unit) R, @specialized M](input: I)(implicit r: LogRenderer[I, V, R, M]): R def putValue[I, V, R, S](v: V)(implicit r: LogRenderer[I, V, R, S]): S = r.dict(v)(logFields(_)) def putField[I, V, R, S](i: I, name: String)(implicit r: LogRenderer[I, V, R, S]): R = r.sub(name, i)(putValue(_)) @@ -19,7 +17,7 @@ trait LoggedValue { object LoggedValue { implicit val loggable: Loggable[LoggedValue] = new Loggable[LoggedValue] { - def fields[I, V, @sp(Unit) R, M](a: LoggedValue, input: I)(implicit receiver: LogRenderer[I, V, R, M]): R = + def fields[I, V, @specialized(Unit) R, M](a: LoggedValue, input: I)(implicit receiver: LogRenderer[I, V, R, M]): R = a.logFields(input) override def putValue[I, V, R, S](a: LoggedValue, v: V)(implicit r: LogRenderer[I, V, R, S]): S = a.putValue(v) @@ -42,7 +40,7 @@ object LoggedValue { final class LoggedThrowable(cause: Throwable) extends Throwable(cause.getMessage, cause) with LoggedValue { override def toString: String = cause.toString - def logFields[I, V, @sp(Unit) R, @sp M](input: I)(implicit f: LogRenderer[I, V, R, M]): R = + def logFields[I, V, @specialized(Unit) R, @specialized M](input: I)(implicit f: LogRenderer[I, V, R, M]): R = Loggable.throwableLoggable.fields(cause, input) override def typeName: String = cause.getClass.getTypeName diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/Logging.scala b/modules/logging/structured/src/main/scala/tofu/logging/Logging.scala similarity index 88% rename from modules/logging/structured/src/main/scala-2/tofu/logging/Logging.scala rename to modules/logging/structured/src/main/scala/tofu/logging/Logging.scala index 00c4f31de..c3af7508b 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/Logging.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/Logging.scala @@ -4,15 +4,14 @@ import cats.kernel.Monoid import cats.{Applicative, Apply, FlatMap, Id} import org.slf4j.Marker import tofu.compat.unused -import tofu.higherKind.{Function2K, RepresentableK} +import tofu.higherKind.Function2K import tofu.logging.Logging.{Debug, Error, Info, Level, Trace, Warn} import tofu.logging.impl.{EmbedLogging, UniversalContextLogs, UniversalLogging} import tofu.syntax.monadic._ import tofu.syntax.monoidalK._ -import tofu.{Delay, Init, WithContext, higherKind} +import tofu.{Delay, Init, WithContext} import scala.reflect.ClassTag -import scala.annotation.nowarn /** Typeclass equivalent of Logger. May contain specified some Logger instance or try to read it from the context */ @@ -79,18 +78,12 @@ trait ServiceLogging[F[_], Service] extends LoggingBase[F] { final def to[Svc2]: ServiceLogging[F, Svc2] = this.asInstanceOf[ServiceLogging[F, Svc2]] } -object ServiceLogging { - private[this] val representableAny: RepresentableK[ServiceLogging[*[_], Any]] = - higherKind.derived.genRepresentableK[ServiceLogging[*[_], Any]] - +object ServiceLogging extends ServiceLoggingRepresentableKInstances { implicit def initByLogs[I[_], F[_], Svc: ClassTag](implicit logs: Logs[I, F]): Init[I, ServiceLogging[F, Svc]] = new Init[I, ServiceLogging[F, Svc]] { def init: I[ServiceLogging[F, Svc]] = logs.service[Svc] } - final implicit def serviceLoggingRepresentable[Svc]: RepresentableK[ServiceLogging[*[_], Svc]] = - representableAny.asInstanceOf[RepresentableK[ServiceLogging[*[_], Svc]]] - final implicit def byUniversal[F[_], Svc: ClassTag](implicit unilogs: Logging.Make[F]): ServiceLogging[F, Svc] = unilogs.service[Svc] } @@ -105,7 +98,7 @@ trait Logging[F[_]] extends ServiceLogging[F, Nothing] { def asLogging: Logging[F] = this } -object Logging { +object Logging extends LoggingRepresentableKInstances { type Make[F[_]] = Logs[Id, F] @@ -134,8 +127,8 @@ object Logging { type ForService[F[_], Svc] <: Logging[F] - type Safe[F[_, _]] = Logging[F[Nothing, *]] - type SafeBase[F[_, _]] = LoggingBase[F[Nothing, *]] + type Safe[F[_, _]] = Logging[F[Nothing, _]] + type SafeBase[F[_, _]] = LoggingBase[F[Nothing, _]] def apply[F[_]](implicit logging: Logging[F]): Logging[F] = logging @@ -144,13 +137,10 @@ object Logging { /** having two logging implementation call `first` after `second` */ def combine[F[_]: Apply](first: Logging[F], second: Logging[F]): Logging[F] = - first.zipWithK(second)(Function2K[F, F, F](_ *> _)) + first.zipWithK[F, F](second)(Function2K[F, F, F](_ *> _)) def flatten[F[_]: FlatMap](underlying: F[Logging[F]]): Logging[F] = new EmbedLogging[F](underlying) - @nowarn("cat=w-flag-self-implicit") - implicit val loggingRepresentable: RepresentableK[Logging] = higherKind.derived.genRepresentableK[Logging] - implicit def loggingMonoid[F[_]: Applicative]: Monoid[Logging[F]] = new Monoid[Logging[F]] { val empty: Logging[F] = Logging.empty[F] def combine(x: Logging[F], y: Logging[F]): Logging[F] = Logging.combine(x, y) diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingCompanion.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggingCompanion.scala similarity index 73% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LoggingCompanion.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LoggingCompanion.scala index af7763d9c..25d826b23 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingCompanion.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LoggingCompanion.scala @@ -8,6 +8,7 @@ import cats.{Functor, Id, Monad} import tofu.higherKind.{Function2K, Mid, MonoidalK} import tofu.syntax.monadic._ import tofu.syntax.monoidalK._ +import tofu.higherKind.HKAny /** Mix-in trait that supposed to be extended by companion of service * @@ -15,7 +16,7 @@ import tofu.syntax.monoidalK._ * {{{class FooService[F[_] : FooService.Log] object FooService extends LoggingCompanion[FooService]}}} */ trait LoggingCompanion[U[_[_]]] { - type Log[F[_]] = ServiceLogging[F, U[Any]] + type Log[F[_]] = ServiceLogging[F, U[HKAny]] implicit def toLogMidOps[F[_]](uf: U[F]): LogMidOps[U, F] = new LogMidOps(uf) @@ -24,13 +25,13 @@ trait LoggingCompanion[U[_[_]]] { svc: ClassTag[U[F]], U: FunctorK[U], UM: LoggingMid.Of[U] - ): U[Mid[F, *]] = Logging.mid.in[U, Id, F] + ): U[Mid[F, _]] = Logging.mid.in[U, Id, F] def logMidNamed[F[_]: Monad](name: String)(implicit L: Logging.Make[F], U: FunctorK[U], UM: LoggingMid.Of[U] - ): U[Mid[F, *]] = Logging.mid.named[U, Id, F](name) + ): U[Mid[F, _]] = Logging.mid.named[U, Id, F](name) def logErrMid[F[+_]: Monad, E](implicit logs: Logging.Make[F], @@ -38,27 +39,27 @@ trait LoggingCompanion[U[_[_]]] { lmid: LoggingErrMid.Of[U, E], errs: Errors[F, E], U: FunctorK[U], - ): U[Mid[F, *]] = Logging.mid.errIn[U, Id, F, E] + ): U[Mid[F, _]] = Logging.mid.errIn[U, Id, F, E] def logErrMidNamed[F[+_]: Monad, E](name: String)(implicit logs: Logging.Make[F], lmid: LoggingErrMid.Of[U, E], errs: Errors[F, E], U: FunctorK[U], - ): U[Mid[F, *]] = Logging.mid.namedErr[U, Id, F, E](name) + ): U[Mid[F, _]] = Logging.mid.namedErr[U, Id, F, E](name) def logMidIn[I[_]: Functor, F[_]: Monad](implicit L: Logs[I, F], svc: ClassTag[U[F]], U: FunctorK[U], UM: LoggingMid.Of[U] - ): I[U[Mid[F, *]]] = Logging.mid.in[U, I, F] + ): I[U[Mid[F, _]]] = Logging.mid.in[U, I, F] def logMidNamedIn[I[_]: Functor, F[_]: Monad](name: String)(implicit L: Logs[I, F], U: FunctorK[U], UM: LoggingMid.Of[U] - ): I[U[Mid[F, *]]] = Logging.mid.named[U, I, F](name) + ): I[U[Mid[F, _]]] = Logging.mid.named[U, I, F](name) def logErrMidIn[I[_]: Functor, F[+_]: Monad, E](implicit logs: Logs[I, F], @@ -66,14 +67,14 @@ trait LoggingCompanion[U[_[_]]] { lmid: LoggingErrMid.Of[U, E], errs: Errors[F, E], U: FunctorK[U], - ): I[U[Mid[F, *]]] = Logging.mid.errIn[U, I, F, E] + ): I[U[Mid[F, _]]] = Logging.mid.errIn[U, I, F, E] def logErrMidNamedIn[I[_]: Functor, F[+_]: Monad, E](name: String)(implicit logs: Logs[I, F], lmid: LoggingErrMid.Of[U, E], errs: Errors[F, E], U: FunctorK[U], - ): I[U[Mid[F, *]]] = Logging.mid.namedErr[U, I, F, E](name) + ): I[U[Mid[F, _]]] = Logging.mid.namedErr[U, I, F, E](name) } @@ -86,7 +87,7 @@ class LogMidOps[U[f[_]], F[_]](private val uf: U[F]) extends AnyVal { F: Monad[F] ): U[F] = { implicit val FL: Logging[F] = L.forService[U[F]] - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.around(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingMid, F]((l, fx) => l.around(fx))) } def attachLogsNamed(name: String)(implicit @@ -96,7 +97,7 @@ class LogMidOps[U[f[_]], F[_]](private val uf: U[F]) extends AnyVal { F: Monad[F] ): U[F] = { implicit val FL: Logging[F] = L.byName(name) - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.around(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingMid, F]((l, fx) => l.around(fx))) } def attachLogsIn[I[_]](implicit @@ -107,7 +108,7 @@ class LogMidOps[U[f[_]], F[_]](private val uf: U[F]) extends AnyVal { U: MonoidalK[U], F: Monad[F] ): I[U[F]] = L.forService[U[F]].map { implicit logging => - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.around(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingMid, F]((l, fx) => l.around(fx))) } def attachLogsNamedIn[I[_]](name: String)(implicit @@ -117,11 +118,11 @@ class LogMidOps[U[f[_]], F[_]](private val uf: U[F]) extends AnyVal { U: MonoidalK[U], F: Monad[F] ): I[U[F]] = L.byName(name).map { implicit logging => - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.around(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingMid, F]((l, fx) => l.around(fx))) } def attachErrLogs[E](implicit - UL: U[LoggingErrMid[E, *]], + UL: U[LoggingErrMid[E, _]], cls: ClassTag[U[F]], L: Logging.Make[F], U: MonoidalK[U], @@ -129,40 +130,40 @@ class LogMidOps[U[f[_]], F[_]](private val uf: U[F]) extends AnyVal { FE: Errors[F, E], ): U[F] = { implicit val FL: Logging[F] = L.forService[U[F]] - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.aroundErr(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingErrMid[E, _], F]((l, fx) => l.aroundErr(fx))) } def attachErrLogsNamed[E](name: String)(implicit - UL: U[LoggingErrMid[E, *]], + UL: U[LoggingErrMid[E, _]], L: Logging.Make[F], U: MonoidalK[U], F: Monad[F], FE: Errors[F, E], ): U[F] = { implicit val FL: Logging[F] = L.byName(name) - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.aroundErr(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingErrMid[E, _], F]((l, fx) => l.aroundErr(fx))) } def attachErrLogsIn[I[_], E](implicit I: Functor[I], - UL: U[LoggingErrMid[E, *]], + UL: U[LoggingErrMid[E, _]], cls: ClassTag[U[F]], L: Logs[I, F], U: MonoidalK[U], F: Monad[F], FE: Errors[F, E], ): I[U[F]] = L.forService[U[F]].map { implicit logging => - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.aroundErr(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingErrMid[E, _], F]((l, fx) => l.aroundErr(fx))) } def attachErrLogsNamedIn[I[_], E](name: String)(implicit I: Functor[I], - UL: U[LoggingErrMid[E, *]], + UL: U[LoggingErrMid[E, _]], L: Logs[I, F], U: MonoidalK[U], F: Monad[F], FE: Errors[F, E], ): I[U[F]] = L.byName(name).map { implicit logging => - UL.zipWithK(uf)(Function2K.apply((l, fx) => l.aroundErr(fx))) + UL.zipWithK(uf)(Function2K.apply[LoggingErrMid[E, _], F]((l, fx) => l.aroundErr(fx))) } } diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingMid.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggingMid.scala similarity index 74% rename from modules/logging/structured/src/main/scala-2/tofu/logging/LoggingMid.scala rename to modules/logging/structured/src/main/scala/tofu/logging/LoggingMid.scala index e69e8d75f..07effbb37 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/LoggingMid.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LoggingMid.scala @@ -3,7 +3,6 @@ package tofu.logging import cats.Monad import tofu.Errors import tofu.higherKind.Mid -import tofu.higherKind.derived.HigherKindedMacros /** Logging middleware Alg[LoggingMid] is a special form of implicit evidence of injectable logging support generally * you don't need `Logging` instance to derive this so choice of logging postponed until this middleware is attached to @@ -15,9 +14,8 @@ abstract class LoggingMid[A] { def toMid[F[_]: Monad: LoggingBase]: Mid[F, A] = around(_) } -object LoggingMid extends builder.LoggingMidBuilder.DefaultImpl { +object LoggingMid extends builder.LoggingMidBuilder.DefaultImpl with LoggingMidMacroInstances { type Result[A] = LoggingMid[A] - def instance[U[_[_]]]: U[LoggingMid] = macro HigherKindedMacros.factorizeThis[U] type Of[U[_[_]]] = U[LoggingMid] } @@ -27,16 +25,16 @@ object LoggingMid extends builder.LoggingMidBuilder.DefaultImpl { * until this middleware is attached to the core instance */ abstract class LoggingErrMid[E, A] extends LoggingMid[A] { - def aroundErr[F[_]: Monad: Errors[*[_], E]: LoggingBase](fa: F[A]): F[A] + def aroundErr[F[_]: Monad: ({ type L[x[_]] = Errors[x, E] })#L: LoggingBase](fa: F[A]): F[A] def around[F[_]: Monad: LoggingBase](fa: F[A]): F[A] = around(fa) - def toMid[F[_]: Monad: Errors[*[_], E]: LoggingBase]: Mid[F, A] = aroundErr(_) + def toMid[F[_]: Monad: ({ type L[x[_]] = Errors[x, E] })#L: LoggingBase]: Mid[F, A] = aroundErr(_) } object LoggingErrMid { - type Of[U[_[_]], E] = U[LoggingErrMid[E, *]] - type Try[U[_[_]]] = U[LoggingErrMid[Throwable, *]] + type Of[U[_[_]], E] = U[LoggingErrMid[E, _]] + type Try[U[_[_]]] = U[LoggingErrMid[Throwable, _]] object Try extends builder.LoggingErrMidBuilder.DefaultImpl[Throwable] } diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/Logs.scala b/modules/logging/structured/src/main/scala/tofu/logging/Logs.scala similarity index 95% rename from modules/logging/structured/src/main/scala-2/tofu/logging/Logs.scala rename to modules/logging/structured/src/main/scala/tofu/logging/Logs.scala index a0e7445b1..97b0b7a30 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/Logs.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/Logs.scala @@ -8,6 +8,7 @@ import tofu.logging.internal.{LogsInstances, LogsInstances0, LogsInvariantSyntax import tofu.syntax.monadic._ import scala.reflect.ClassTag +import tofu.higherKind.HKAny /** A helper for creating instances of [[tofu.logging.Logging]], defining a way these instances will behave while doing * logging. Can create instances either on a by-name basic or a type tag basic. An instance of [[tofu.logging.Logs]] @@ -46,16 +47,16 @@ trait Logs[+I[_], F[_]] extends LogsVOps[I, F] { * * val serviceLog = logs.of[Service] //ServiceLogging[ }}} */ - final def of[Svc[_[_]]](implicit tag: ClassTag[Svc[Any]]): I[ServiceLogging[F, Svc[Any]]] = - service[Svc[Any]] + final def of[Svc[_[_]]](implicit tag: ClassTag[Svc[HKAny]]): I[ServiceLogging[F, Svc[HKAny]]] = + service[Svc[HKAny]] } object Logs extends LogsInstances with LogsInstances0 { @deprecated("Use Logging.Make[F]", since = "0.10.4") type Universal[F[_]] = Logs[Id, F] - type Safe[I[_], F[_, _]] = Logs[I, F[Nothing, *]] - type SafeUniversal[F[_, _]] = Logs[Id, F[Nothing, *]] + type Safe[I[_], F[_, _]] = Logs[I, F[Nothing, _]] + type SafeUniversal[F[_, _]] = Logs[Id, F[Nothing, _]] def apply[I[_], F[_]](implicit logs: Logs[I, F]): Logs[I, F] = logs diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/TethysBuilder.scala b/modules/logging/structured/src/main/scala/tofu/logging/TethysBuilder.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/TethysBuilder.scala rename to modules/logging/structured/src/main/scala/tofu/logging/TethysBuilder.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/atom/AtomLogger.scala b/modules/logging/structured/src/main/scala/tofu/logging/atom/AtomLogger.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/atom/AtomLogger.scala rename to modules/logging/structured/src/main/scala/tofu/logging/atom/AtomLogger.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/bi/LoggingBiCompanion.scala b/modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala similarity index 76% rename from modules/logging/structured/src/main/scala-2/tofu/logging/bi/LoggingBiCompanion.scala rename to modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala index c5911a5ef..53b8ae2b7 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/bi/LoggingBiCompanion.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala @@ -6,12 +6,11 @@ import scala.reflect.ClassTag import cats.{Functor, Id} import tofu.control.Bind import tofu.higherKind.bi.{BiMid, Fun2BK, FunctorBK, MonoidalBK} -import tofu.logging.ServiceLogging import tofu.syntax.functorbk._ import tofu.syntax.monadic._ trait LoggingBiCompanion[U[_[_, _]]] { - type Log[F[_, _]] = ServiceLogging[F[Nothing, *], U[Any]] + type Log[F[_, _]] = ServiceLogging[F[Nothing, _], U[({ type L[_, _] = Any })#L]] implicit def toBiLogBiMidOps[F[+_, +_]](uf: U[F]): LogBiMidOps[U, F] = new LogBiMidOps(uf) @@ -20,26 +19,26 @@ trait LoggingBiCompanion[U[_[_, _]]] { UCls: ClassTag[U[F]], lmid: U[LoggingBiMid], U: FunctorBK[U], - ): U[BiMid[F, *, *]] = Logging.mid.inBi[U, Id, F] + ): U[BiMid[F, _, _]] = Logging.mid.inBi[U, Id, F] def bimidNamed[F[+_, +_]: Bind](name: String)(implicit logs: Logs.SafeUniversal[F], lmid: U[LoggingBiMid], U: FunctorBK[U], - ): U[BiMid[F, *, *]] = Logging.mid.namedBi[U, Id, F](name) + ): U[BiMid[F, _, _]] = Logging.mid.namedBi[U, Id, F](name) def bimidIn[I[_]: Functor, F[+_, +_]: Bind](implicit logs: Logs.Safe[I, F], UCls: ClassTag[U[F]], lmid: U[LoggingBiMid], U: FunctorBK[U], - ): I[U[BiMid[F, *, *]]] = Logging.mid.inBi[U, I, F] + ): I[U[BiMid[F, _, _]]] = Logging.mid.inBi[U, I, F] def bimidNamedIn[I[_]: Functor, F[+_, +_]: Bind](name: String)(implicit logs: Logs.Safe[I, F], lmid: U[LoggingBiMid], U: FunctorBK[U], - ): I[U[BiMid[F, *, *]]] = Logging.mid.namedBi[U, I, F](name) + ): I[U[BiMid[F, _, _]]] = Logging.mid.namedBi[U, I, F](name) } class LogBiMidOps[U[f[_, _]], F[+_, +_]](private val uf: U[F]) extends AnyVal { @@ -51,7 +50,7 @@ class LogBiMidOps[U[f[_, _]], F[+_, +_]](private val uf: U[F]) extends AnyVal { F: Bind[F], ): U[F] = { implicit val logging: Logging.Safe[F] = logs.forService[U[F]] - UL.map2b(uf)(Fun2BK.apply((l, fx) => l.around(fx))) + UL.map2b(uf)(Fun2BK.apply[LoggingBiMid, F]((l, fx) => l.around(fx))) } def attachLogsIn[I[_]: Functor](implicit @@ -61,7 +60,7 @@ class LogBiMidOps[U[f[_, _]], F[+_, +_]](private val uf: U[F]) extends AnyVal { U: MonoidalBK[U], F: Bind[F], ): I[U[F]] = logs.forService[U[F]].map { implicit logging => - UL.map2b(uf)(Fun2BK.apply((l, fx) => l.around(fx))) + UL.map2b(uf)(Fun2BK.apply[LoggingBiMid, F]((l, fx) => l.around(fx))) } def attachLogsNamed(name: String)(implicit @@ -71,7 +70,7 @@ class LogBiMidOps[U[f[_, _]], F[+_, +_]](private val uf: U[F]) extends AnyVal { F: Bind[F], ): U[F] = { implicit val logging: Logging.Safe[F] = logs.byName(name) - UL.map2b(uf)(Fun2BK.apply((l, fx) => l.around(fx))) + UL.map2b(uf)(Fun2BK.apply[LoggingBiMid, F]((l, fx) => l.around(fx))) } def attachLogsNamedIn[I[_]: Functor](name: String)(implicit @@ -80,6 +79,6 @@ class LogBiMidOps[U[f[_, _]], F[+_, +_]](private val uf: U[F]) extends AnyVal { U: MonoidalBK[U], F: Bind[F], ): I[U[F]] = logs.byName(name).map { implicit logging => - UL.map2b(uf)(Fun2BK.apply((l, fx) => l.around(fx))) + UL.map2b(uf)(Fun2BK.apply[LoggingBiMid, F]((l, fx) => l.around(fx))) } } diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/bi/LoggingBiMid.scala b/modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiMid.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/bi/LoggingBiMid.scala rename to modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiMid.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/builder/LoggingBiMidBuilder.scala b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala similarity index 84% rename from modules/logging/structured/src/main/scala-2/tofu/logging/builder/LoggingBiMidBuilder.scala rename to modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala index 92db514b6..5be53bff0 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/builder/LoggingBiMidBuilder.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala @@ -7,11 +7,12 @@ import tofu.logging.bi.LoggingBiMid import tofu.logging.impl.ArgsLoggable import tofu.syntax.bindInv._ +import scala.collection.immutable.Seq import scala.collection.mutable.Buffer import scala.reflect.ClassTag trait BiBuilder[+T[_, _]] { - def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[Any]]): BiPrepared[Alg, T] + def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[({ type L[_, _] = Any })#L]]): BiPrepared[Alg, T] } trait BiMethod[U[f[_, _]], Err, Res, +T[_, _]] { @@ -28,24 +29,25 @@ abstract class LoggingBiMidBuilder extends BiBuilder[LoggingBiMid] { /** do some logging upon enter to method invocation */ def onEnter[F[+_, +_]: Logging.SafeBase]( - cls: Class[_], + cls: Class[?], method: String, args: Seq[(String, LoggedValue)] ): F[Nothing, Unit] /** do some logging after leaving method invocation with known result or error */ def onLeave[F[+_, +_]: Logging.SafeBase]( - cls: Class[_], + cls: Class[?], method: String, args: Seq[(String, LoggedValue)], res: LoggedValue, ok: Boolean ): F[Nothing, Unit] - def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[Any]]) = new PreparedImpl[Alg](Alg.runtimeClass) + def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[({ type L[_, _] = Any })#L]]) = + new PreparedImpl[Alg](Alg.runtimeClass) protected class MethodImpl[U[f[_, _]], Err: Loggable, Res: Loggable]( - cls: Class[_], + cls: Class[?], method: String, args: Buffer[(String, LoggedValue)] ) extends BiMethod[U, Err, Res, LoggingBiMid] { @@ -66,7 +68,7 @@ abstract class LoggingBiMidBuilder extends BiBuilder[LoggingBiMid] { } } - class PreparedImpl[U[f[_, _]]](cls: Class[_]) extends BiPrepared[U, LoggingBiMid] { + class PreparedImpl[U[f[_, _]]](cls: Class[?]) extends BiPrepared[U, LoggingBiMid] { def start[Err: Loggable, Res: Loggable](method: String) = new MethodImpl[U, Err, Res](cls, method, Buffer()) } } @@ -75,12 +77,12 @@ object LoggingBiMidBuilder { class CustomLogLevel(logLevel: Level, errorLogLevel: Level) extends LoggingBiMidBuilder { - override def onEnter[F[+_, +_]](cls: Class[_], method: String, args: Seq[(String, LoggedValue)])(implicit + override def onEnter[F[+_, +_]](cls: Class[?], method: String, args: Seq[(String, LoggedValue)])(implicit F: Logging.SafeBase[F] ): F[Nothing, Unit] = F.write(logLevel, "entering {} {}", method, new ArgsLoggable(args)) override def onLeave[F[+_, +_]]( - cls: Class[_], + cls: Class[?], method: String, args: Seq[(String, LoggedValue)], res: LoggedValue, diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/builder/LoggingMidBuilder.scala b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala similarity index 79% rename from modules/logging/structured/src/main/scala-2/tofu/logging/builder/LoggingMidBuilder.scala rename to modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala index 6196fb5ba..0e480d9b3 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/builder/LoggingMidBuilder.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala @@ -1,6 +1,7 @@ package tofu.logging package builder +import scala.collection.immutable.Seq import scala.collection.mutable import scala.reflect.ClassTag import tofu.syntax.monadic._ @@ -9,10 +10,10 @@ import tofu.Errors import tofu.syntax.handle._ import impl.ArgsLoggable import tofu.logging.Logging.Level -import tofu.logging.LoggingBase +import tofu.higherKind.HKAny trait Builder[+T[_]] { - def prepare[Alg[_[_]]](implicit Alg: ClassTag[Alg[Any]]): Prepared[Alg, T] + def prepare[Alg[_[_]]](implicit Alg: ClassTag[Alg[HKAny]]): Prepared[Alg, T] } trait Method[U[f[_]], Res, +T[_]] { @@ -29,20 +30,21 @@ trait Prepared[U[f[_]], +T[_]] { trait LoggingMidBuilder extends Builder[LoggingMid] { /** do some logging upon enter to method invocation */ - def onEnter[F[_]: LoggingBase](cls: Class[_], method: String, args: Seq[(String, LoggedValue)]): F[Unit] + def onEnter[F[_]: LoggingBase](cls: Class[?], method: String, args: Seq[(String, LoggedValue)]): F[Unit] /** do some logging after leaving method invocation with known result */ def onLeave[F[_]: LoggingBase]( - cls: Class[_], + cls: Class[?], method: String, args: Seq[(String, LoggedValue)], res: LoggedValue ): F[Unit] - def prepare[Alg[_[_]]](implicit Alg: ClassTag[Alg[Any]]) = new PreparedImpl[Alg](Alg.runtimeClass) + def prepare[Alg[_[_]]](implicit Alg: ClassTag[Alg[HKAny]]): Prepared[Alg, LoggingMid] = + new PreparedImpl[Alg](Alg.runtimeClass) protected class MethodImpl[U[f[_]], Res: Loggable]( - cls: Class[_], + cls: Class[?], method: String, args: mutable.Buffer[(String, LoggedValue)] ) extends Method[U, Res, LoggingMid] { @@ -59,18 +61,18 @@ trait LoggingMidBuilder extends Builder[LoggingMid] { } } - protected class PreparedImpl[U[f[_]]](cls: Class[_]) extends Prepared[U, LoggingMid] { + protected class PreparedImpl[U[f[_]]](cls: Class[?]) extends Prepared[U, LoggingMid] { def start[Res: Loggable](method: String): MethodImpl[U, Res] = new MethodImpl(cls, method, mutable.Buffer()) } } object LoggingMidBuilder { trait Default extends LoggingMidBuilder { - def onEnter[F[_]](cls: Class[_], method: String, args: Seq[(String, LoggedValue)])(implicit + def onEnter[F[_]](cls: Class[?], method: String, args: Seq[(String, LoggedValue)])(implicit F: LoggingBase[F] ): F[Unit] = F.debug("entering {} {}", method, new ArgsLoggable(args)) - def onLeave[F[_]](cls: Class[_], method: String, args: Seq[(String, LoggedValue)], res: LoggedValue)(implicit + def onLeave[F[_]](cls: Class[?], method: String, args: Seq[(String, LoggedValue)], res: LoggedValue)(implicit F: LoggingBase[F] ): F[Unit] = F.debug("leaving {} {} with result {}", method, new ArgsLoggable(args), res) } @@ -80,11 +82,11 @@ object LoggingMidBuilder { trait CustomLevel extends LoggingMidBuilder { def onLog[F[_]](message: String, values: LoggedValue*)(implicit F: LoggingBase[F]): F[Unit] - def onEnter[F[_]](cls: Class[_], method: String, args: Seq[(String, LoggedValue)])(implicit + def onEnter[F[_]](cls: Class[?], method: String, args: Seq[(String, LoggedValue)])(implicit F: LoggingBase[F] ): F[Unit] = onLog("entering {} {}", method, new ArgsLoggable(args)) - def onLeave[F[_]](cls: Class[_], method: String, args: Seq[(String, LoggedValue)], res: LoggedValue)(implicit + def onLeave[F[_]](cls: Class[?], method: String, args: Seq[(String, LoggedValue)], res: LoggedValue)(implicit F: LoggingBase[F] ): F[Unit] = onLog("leaving {} {} with result {}", method, new ArgsLoggable(args), res) } @@ -95,32 +97,33 @@ object LoggingMidBuilder { } } -trait LoggingErrMidBuilder[E] extends LoggingMidBuilder with Builder[LoggingErrMid[E, *]] { +trait LoggingErrMidBuilder[E] extends LoggingMidBuilder with Builder[LoggingErrMid[E, _]] { def onFault[F[_]: LoggingBase]( - cls: Class[_], + cls: Class[?], method: String, args: Seq[(String, LoggedValue)], err: E ): F[Unit] - override def prepare[Alg[_[_]]](implicit Alg: ClassTag[Alg[Any]]) = new PreparedErr[Alg](Alg.runtimeClass) + override def prepare[Alg[_[_]]](implicit Alg: ClassTag[Alg[HKAny]]): Prepared[Alg, LoggingErrMid[E, _]] = + new PreparedErr[Alg](Alg.runtimeClass) protected class MethodErrImpl[U[f[_]], Res: Loggable]( - cls: Class[_], + cls: Class[?], method: String, args: mutable.Buffer[(String, LoggedValue)] - ) extends MethodImpl[U, Res](cls, method, args) with Method[U, Res, LoggingErrMid[E, *]] { + ) extends MethodImpl[U, Res](cls, method, args) with Method[U, Res, LoggingErrMid[E, _]] { override def result: LoggingErrMid[E, Res] = new LoggingErrMid[E, Res] { private[this] val argSeq = args.toSeq - def aroundErr[F[_]: Monad: Errors[*[_], E]: LoggingBase](fa: F[Res]): F[Res] = + def aroundErr[F[_]: Monad: ({ type L[x[_]] = Errors[x, E] })#L: LoggingBase](fa: F[Res]): F[Res] = onEnter(cls, method, argSeq) *> fa.onError(onFault(cls, method, argSeq, _: E)) .flatTap(res => onLeave(cls, method, argSeq, res)) } } - class PreparedErr[U[f[_]]](cls: Class[_]) extends super.PreparedImpl[U](cls) with Prepared[U, LoggingErrMid[E, *]] { + class PreparedErr[U[f[_]]](cls: Class[?]) extends super.PreparedImpl[U](cls) with Prepared[U, LoggingErrMid[E, _]] { override def start[Res: Loggable](method: String): MethodErrImpl[U, Res] = new MethodErrImpl(cls, method, mutable.Buffer()) } @@ -131,7 +134,7 @@ object LoggingErrMidBuilder { implicit def errLoggable: Loggable[E] def onFault[F[_]]( - cls: Class[_], + cls: Class[?], method: String, args: Seq[(String, LoggedValue)], err: E @@ -148,7 +151,7 @@ object LoggingErrMidBuilder { def onFaultLog[F[_]: LoggingBase](message: String, values: LoggedValue*): F[Unit] def onFault[F[_]]( - cls: Class[_], + cls: Class[?], method: String, args: Seq[(String, LoggedValue)], err: E diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ArgsLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/ArgsLoggable.scala similarity index 92% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/ArgsLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/ArgsLoggable.scala index c368eb656..4e929d96a 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ArgsLoggable.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/ArgsLoggable.scala @@ -2,6 +2,8 @@ package tofu.logging.impl import tofu.logging.{LogRenderer, LoggedValue} +import scala.collection.immutable.Seq + class ArgsLoggable(values: Seq[(String, LoggedValue)]) extends LoggedValue { override def shortName: String = "arguments" diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/CachedLogs.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/CachedLogs.scala similarity index 96% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/CachedLogs.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/CachedLogs.scala index 4643e53b8..7c190f1bd 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/CachedLogs.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/CachedLogs.scala @@ -11,7 +11,7 @@ import scala.reflect.{ClassTag, classTag} class CachedLogs[I[_]: Monad: Guarantee, F[_]]( underlying: Logs[I, F], nameCache: QVar[I, Map[String, Logging[F]]], - tagCache: QVar[I, Map[ClassTag[_], Logging[F]]] + tagCache: QVar[I, Map[ClassTag[?], Logging[F]]] ) extends Logs[I, F] { private[this] case object NoneLogging extends Logging[F] { def write(level: Logging.Level, message: String, values: LoggedValue*): F[Unit] = diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ComposedLoggedValue.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/ComposedLoggedValue.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/ComposedLoggedValue.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/ComposedLoggedValue.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextLoggingImpl.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/ContextLoggingImpl.scala similarity index 96% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextLoggingImpl.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/ContextLoggingImpl.scala index f16ca4644..b4f3fa2ab 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextLoggingImpl.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/ContextLoggingImpl.scala @@ -7,7 +7,7 @@ import cats.syntax.applicative._ import org.slf4j.{Logger, Marker} import scala.annotation.nowarn -@nowarn("cat=lint-infer-any") +@nowarn("msg=a type was inferred to be `Object`") //cat=lint-infer-any filter does not work for Scala 3 class ContextLoggingImpl[F[_]: Applicative, C: Loggable, Service](context: F WithContext C, logger: Logger) extends LoggingImpl[F](logger) { diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextMarker.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/ContextMarker.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextMarker.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/ContextMarker.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextSyncLoggingImpl.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/ContextSyncLoggingImpl.scala similarity index 97% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextSyncLoggingImpl.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/ContextSyncLoggingImpl.scala index 89255d642..9cefd41b4 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContextSyncLoggingImpl.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/ContextSyncLoggingImpl.scala @@ -7,7 +7,7 @@ import tofu.syntax.monadic._ import cats.Monad import scala.annotation.nowarn -@nowarn("cat=lint-infer-any") +@nowarn("msg=a type was inferred to be `Object`") //cat=lint-infer-any filter does not work for Scala 3 class ContextSyncLoggingImpl[F[_]: Monad, C: Loggable](context: F WithContext C, logger: Logger)(implicit F: Delay[F]) extends LoggingImpl[F](logger) { diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContramapLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/ContramapLoggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/ContramapLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/ContramapLoggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/EmbedLogging.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/EmbedLogging.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/EmbedLogging.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/EmbedLogging.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/EmptyLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/EmptyLoggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/EmptyLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/EmptyLoggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/FilterLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/FilterLoggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/FilterLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/FilterLoggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/HiddenLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/HiddenLoggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/HiddenLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/HiddenLoggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/LoggingImpl.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/LoggingImpl.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/LoggingImpl.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/LoggingImpl.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/LoggingMidFunctions.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/LoggingMidFunctions.scala similarity index 65% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/LoggingMidFunctions.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/LoggingMidFunctions.scala index 562d4a08b..fd83e8cfd 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/LoggingMidFunctions.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/LoggingMidFunctions.scala @@ -21,34 +21,37 @@ object LoggingMidFunctions { logs: Logs[I, F], UCls: ClassTag[U[F]], lmid: U[LoggingMid], - ): I[U[Mid[F, *]]] = logs.forService[U[F]].map(implicit logging => lmid.mapK(funK(_.toMid))) + ): I[U[Mid[F, _]]] = + logs.forService[U[F]].map(implicit logging => lmid.mapK(funK[LoggingMid, Mid[F, _]](_.toMid))) def named[U[_[_]]: FunctorK, I[_]: Functor, F[_]: Monad](name: String)(implicit logs: Logs[I, F], lmid: U[LoggingMid], - ): I[U[Mid[F, *]]] = logs.byName(name).map(implicit logging => lmid.mapK(funK(_.toMid))) + ): I[U[Mid[F, _]]] = logs.byName(name).map(implicit logging => lmid.mapK(funK[LoggingMid, Mid[F, _]](_.toMid))) def inBi[U[_[_, _]]: FunctorBK, I[_]: Functor, F[+_, +_]: Bind](implicit logs: Logs.Safe[I, F], UCls: ClassTag[U[F]], lmid: U[LoggingBiMid], - ): I[U[BiMid[F, *, *]]] = logs.forService[U[F]].map(implicit logging => lmid.mapb(FunBK.apply(_.toMid))) + ): I[U[BiMid[F, _, _]]] = logs.forService[U[F]].map(implicit logging => lmid.mapb(FunBK.apply[LoggingBiMid](_.toMid))) def namedBi[U[_[_, _]]: FunctorBK, I[_]: Functor, F[+_, +_]: Bind](name: String)(implicit logs: Logs.Safe[I, F], lmid: U[LoggingBiMid], - ): I[U[BiMid[F, *, *]]] = logs.byName(name).map(implicit logging => lmid.mapb(FunBK.apply(_.toMid))) + ): I[U[BiMid[F, _, _]]] = logs.byName(name).map(implicit logging => lmid.mapb(FunBK.apply[LoggingBiMid](_.toMid))) def errIn[U[_[_]]: FunctorK, I[_]: Functor, F[+_]: Monad, E](implicit logs: Logs[I, F], UCls: ClassTag[U[F]], lmid: LoggingErrMid.Of[U, E], errs: Errors[F, E], - ): I[U[Mid[F, *]]] = logs.forService[U[F]].map(implicit logging => lmid.mapK(funK(_.toMid[F]))) + ): I[U[Mid[F, _]]] = + logs.forService[U[F]].map(implicit logging => lmid.mapK(funK[LoggingErrMid[E, _], Mid[F, _]](_.toMid[F]))) def namedErr[U[_[_]]: FunctorK, I[_]: Functor, F[+_]: Monad, E](name: String)(implicit logs: Logs[I, F], lmid: LoggingErrMid.Of[U, E], errs: Errors[F, E], - ): I[U[Mid[F, *]]] = logs.byName(name).map(implicit logging => lmid.mapK(funK(_.toMid[F]))) + ): I[U[Mid[F, _]]] = + logs.byName(name).map(implicit logging => lmid.mapK(funK[LoggingErrMid[E, _], Mid[F, _]](_.toMid[F]))) } diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/NamedLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/NamedLoggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/NamedLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/NamedLoggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/PlusLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/PlusLoggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/PlusLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/PlusLoggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/SingletonLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/SingletonLoggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/SingletonLoggable.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/SingletonLoggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/SyncLogging.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/SyncLogging.scala similarity index 96% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/SyncLogging.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/SyncLogging.scala index 3f1e4ee58..27f18c2a1 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/SyncLogging.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/SyncLogging.scala @@ -7,7 +7,7 @@ import cats.Monad import tofu.Delay import scala.annotation.nowarn -@nowarn("cat=lint-infer-any") +@nowarn("msg=a type was inferred to be `Object`") //cat=lint-infer-any filter does not work for Scala 3 class SyncLogging[F[_]: Monad](logger: Logger)(implicit F: Delay[F]) extends LoggingImpl[F](logger) { override def trace(message: String, values: LoggedValue*): F[Unit] = F.delay(logger.trace(message, values: _*)).whenA(traceEnabled) diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/UniversalEmbedLogs.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalEmbedLogs.scala similarity index 99% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/UniversalEmbedLogs.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalEmbedLogs.scala index 74ffbb46a..d6a79e5b7 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/UniversalEmbedLogs.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalEmbedLogs.scala @@ -1,4 +1,5 @@ package tofu.logging.impl + import cats.{FlatMap, Id} import tofu.lift.Lift import tofu.logging.{Logging, Logs} diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/UniversalLogging.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalLogging.scala similarity index 97% rename from modules/logging/structured/src/main/scala-2/tofu/logging/impl/UniversalLogging.scala rename to modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalLogging.scala index 2121d89a7..9223186f4 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/impl/UniversalLogging.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalLogging.scala @@ -6,8 +6,9 @@ import org.slf4j.{Logger, LoggerFactory, Marker} import tofu.logging.Logging.{Debug, Error, Info, Trace, Warn} import tofu.{Delay, WithContext} import scala.annotation.nowarn +import scala.collection.immutable.Seq -@nowarn("cat=lint-infer-any") +@nowarn("msg=a type was inferred to be `Object`") //cat=lint-infer-any filter does not work for Scala 3 object UniversalLogging { private[impl] final def enabled(level: Logging.Level, logger: Logger): Boolean = level match { case Trace => logger.isTraceEnabled() diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsInstances.scala b/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInstances.scala similarity index 66% rename from modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsInstances.scala rename to modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInstances.scala index 10e3d8fc4..9d88cb1af 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsInstances.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInstances.scala @@ -3,9 +3,8 @@ package tofu.logging.internal import cats.data.Tuple2K import cats.kernel.Monoid import cats.tagless.{ApplyK, FunctorK} -import cats.{Applicative, Apply, Functor, Id, ~>} -import tofu.higherKind -import tofu.higherKind.{Function2K, MonoidalK, Point, RepresentableK} +import cats.{Applicative, Apply, Functor, ~>} +import tofu.higherKind.{Function2K, MonoidalK, Point} import tofu.logging.{Logging, Logs} import cats.tagless.syntax.functorK._ import tofu.syntax.monoidalK._ @@ -13,46 +12,37 @@ import tofu.syntax.monadic._ import scala.reflect.ClassTag -trait LogsInstances { +trait LogsInstances extends LogsRepresentableKInstances { implicit def logsMonoid[I[_]: Applicative, F[_]: Applicative]: Monoid[Logs[I, F]] = new Monoid[Logs[I, F]] { def empty: Logs[I, F] = Logs.empty[I, F] def combine(x: Logs[I, F], y: Logs[I, F]): Logs[I, F] = Logs.combine(x, y) } - private[this] val logs1RepresentableAny: RepresentableK[Logs[*[_], Any]] = - higherKind.derived.genRepresentableK[Logs[*[_], Any]] - - implicit def logs1Representable[Y[_]]: RepresentableK[Logs[*[_], Y]] = - logs1RepresentableAny.asInstanceOf[RepresentableK[Logs[*[_], Y]]] - - implicit val logs2UniversalRepresentable: RepresentableK[Logs[Id, *[_]]] = - higherKind.derived.genRepresentableK[Logs[Id, *[_]]] - - implicit def logs2MonoidalK[Y[_]](implicit Y: Applicative[Y]): MonoidalK[Logs[Y, *[_]]] = + implicit def logs2MonoidalK[Y[_]](implicit Y: Applicative[Y]): MonoidalK[({ type L[x[_]] = Logs[Y, x] })#L] = new Logs2MonoidalK[Y] { def I: Applicative[Y] = Y } } private[logging] trait LogsInstances0 extends LogsInstances1 { - implicit def logs2ApplyK[Y[_]](implicit Y: Apply[Y]): ApplyK[Logs[Y, *[_]]] = + implicit def logs2ApplyK[Y[_]](implicit Y: Apply[Y]): ApplyK[({ type L[x[_]] = Logs[Y, x] })#L] = new Logs2ApplyK[Y] { def I: Apply[Y] = Y } } private[logging] trait LogsInstances1 { - implicit def logs2FunctorK[Y[_]](implicit Y: Functor[Y]): FunctorK[Logs[Y, *[_]]] = + implicit def logs2FunctorK[Y[_]](implicit Y: Functor[Y]): FunctorK[({ type L[x[_]] = Logs[Y, x] })#L] = new Logs2FunctorK[Y] { def I: Functor[Y] = Y } } -trait Logs2FunctorK[Y[_]] extends FunctorK[Logs[Y, *[_]]] { +trait Logs2FunctorK[Y[_]] extends FunctorK[({ type L[x[_]] = Logs[Y, x] })#L] { implicit def I: Functor[Y] def mapK[F[_], G[_]](af: Logs[Y, F])(fk: F ~> G): Logs[Y, G] = new Logs[Y, G] { - override def forService[Svc: ClassTag]: Y[Logging[G]] = af.forService[Svc].map(_.mapK(fk)) + override def forService[Svc: ClassTag]: Y[Logging[G]] = af.forService[Svc].map(a => a.mapK(fk)) def byName(name: String): Y[Logging[G]] = af.byName(name).map(_.mapK(fk)) } } -trait Logs2ApplyK[Y[_]] extends Logs2FunctorK[Y] with ApplyK[Logs[Y, *[_]]] { +trait Logs2ApplyK[Y[_]] extends Logs2FunctorK[Y] with ApplyK[({ type L[x[_]] = Logs[Y, x] })#L] { implicit def I: Apply[Y] def zipWith2K[F[_], G[_], H[_]](af: Logs[Y, F], ag: Logs[Y, G])(f2: Function2K[F, G, H]): Logs[Y, H] = @@ -62,11 +52,11 @@ trait Logs2ApplyK[Y[_]] extends Logs2FunctorK[Y] with ApplyK[Logs[Y, *[_]]] { def byName(name: String): Y[Logging[H]] = (af.byName(name), ag.byName(name)).mapN(_.zipWithK(_)(f2)) } - def productK[F[_], G[_]](af: Logs[Y, F], ag: Logs[Y, G]): Logs[Y, Tuple2K[F, G, *]] = - zipWith2K(af, ag)(Function2K((f, g) => Tuple2K(f, g))) + def productK[F[_], G[_]](af: Logs[Y, F], ag: Logs[Y, G]): Logs[Y, Tuple2K[F, G, _]] = + zipWith2K(af, ag)(Function2K.apply[F, G]((f, g) => Tuple2K(f, g))) } -trait Logs2MonoidalK[Y[_]] extends Logs2ApplyK[Y] with MonoidalK[Logs[Y, *[_]]] { +trait Logs2MonoidalK[Y[_]] extends Logs2ApplyK[Y] with MonoidalK[({ type L[x[_]] = Logs[Y, x] })#L] { implicit def I: Applicative[Y] def pureK[F[_]](p: Point[F]): Logs[Y, F] = new Logs[Y, F] { diff --git a/modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsInvariantSyntax.scala b/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInvariantSyntax.scala similarity index 75% rename from modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsInvariantSyntax.scala rename to modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInvariantSyntax.scala index 39e7dc1b2..d36cb1221 100644 --- a/modules/logging/structured/src/main/scala-2/tofu/logging/internal/LogsInvariantSyntax.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInvariantSyntax.scala @@ -5,11 +5,13 @@ import tofu.Guarantee import tofu.concurrent.{MakeQVar, QVars} import tofu.higherKind.{Mid, Post, Pre} import tofu.lift.Lift -import tofu.logging.impl.{CachedLogs, UniversalEmbedLogs} +import tofu.logging.impl.{CachedLogs} +import tofu.logging.impl.UniversalEmbedLogs import tofu.logging.{Logging, Logs} import scala.reflect.ClassTag import tofu.syntax.monadic._ +import tofu.higherKind.HKAny object LogsInvariantSyntax { final class LogsOps[I[_], F[_]](private val logs: Logs[I, F]) extends AnyVal { @@ -17,7 +19,7 @@ object LogsInvariantSyntax { QVars[I] .of(Map.empty[String, Logging[F]]) .map2( - QVars[I].of(Map.empty[ClassTag[_], Logging[F]]) + QVars[I].of(Map.empty[ClassTag[?], Logging[F]]) )(new CachedLogs[I, F](logs, _, _)) def universal(implicit il: Lift[I, F], F: FlatMap[F]): Logs.Universal[F] = new UniversalEmbedLogs(logs) @@ -34,8 +36,8 @@ object LogsInvariantSyntax { /** Collection of useful methods for creating middleware * {{{logs.logged[Service].mid(implicit l => new Service[Mid[F, *]]{... })}}} */ - final def logged[U[_[_]]](implicit c: ClassTag[U[Any]]): LogWares[U, I, F] = - new LogWares(logs.forService[U[Any]]) + final def logged[U[_[_]]](implicit c: ClassTag[U[HKAny]]): LogWares[U, I, F] = + new LogWares(logs.forService[U[HKAny]]) /** Collection of useful methods for creating middleware * {{{logs.nameLogged[Service]("service").mid(implicit l => new Service[Mid[F, *]]{... })}}} @@ -48,17 +50,17 @@ object LogsInvariantSyntax { class LogWares[U[_[_]], I[_], F[_]](private val made: I[Logging[F]]) extends AnyVal { final def pre( - make: Logging[F] => U[Pre.Unwrap[F, *]] - )(implicit I: Functor[I]): I[U[Pre[F, *]]] = + make: Logging[F] => U[Pre.Unwrap[F, _]] + )(implicit I: Functor[I]): I[U[Pre[F, _]]] = made.map(logging => Pre.wrap(make(logging))) final def post( - make: Logging[F] => U[Post[F, *]] - )(implicit I: Functor[I]): I[U[Post[F, *]]] = + make: Logging[F] => U[Post[F, _]] + )(implicit I: Functor[I]): I[U[Post[F, _]]] = made.map(logging => make(logging)) final def mid( - make: Logging[F] => U[Mid[F, *]] - )(implicit I: Functor[I]): I[U[Mid[F, *]]] = + make: Logging[F] => U[Mid[F, _]] + )(implicit I: Functor[I]): I[U[Mid[F, _]]] = made.map(logging => make(logging)) } diff --git a/modules/logging/structured/src/main/scala/tofu/logging/location/Location.scala b/modules/logging/structured/src/main/scala/tofu/logging/location/Location.scala new file mode 100644 index 000000000..2e5fe296f --- /dev/null +++ b/modules/logging/structured/src/main/scala/tofu/logging/location/Location.scala @@ -0,0 +1,11 @@ +package tofu.logging.location + +import tofu.logging.Loggable + +case class Location(file: String, line: Int, applicationPoint: String) + +object Location extends LocationMacroInstances { + implicit val loggable: Loggable[Location] = Loggable[String].contramap { case Location(file, line, point) => + s"$point@($file:$line)" + } +} diff --git a/modules/logging/structured/src/main/scala/tofu/logging/package.scala b/modules/logging/structured/src/main/scala/tofu/logging/package.scala new file mode 100644 index 000000000..1a4dda738 --- /dev/null +++ b/modules/logging/structured/src/main/scala/tofu/logging/package.scala @@ -0,0 +1,7 @@ +package tofu + +import tofu.higherKind.HKAny + +package object logging { + type ModuleLog[F[_], U[_[_]]] = ServiceLogging[F, U[HKAny]] +} diff --git a/modules/logging/structured/src/main/scala-2/tofu/syntax/location.scala b/modules/logging/structured/src/main/scala/tofu/syntax/location.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/syntax/location.scala rename to modules/logging/structured/src/main/scala/tofu/syntax/location.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/syntax/logRenderer.scala b/modules/logging/structured/src/main/scala/tofu/syntax/logRenderer.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/syntax/logRenderer.scala rename to modules/logging/structured/src/main/scala/tofu/syntax/logRenderer.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/syntax/loggable.scala b/modules/logging/structured/src/main/scala/tofu/syntax/loggable.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/syntax/loggable.scala rename to modules/logging/structured/src/main/scala/tofu/syntax/loggable.scala diff --git a/modules/logging/structured/src/main/scala-2/tofu/syntax/logging.scala b/modules/logging/structured/src/main/scala/tofu/syntax/logging.scala similarity index 100% rename from modules/logging/structured/src/main/scala-2/tofu/syntax/logging.scala rename to modules/logging/structured/src/main/scala/tofu/syntax/logging.scala diff --git a/modules/logging/structured/src/test/scala-2/tofu/logging/LoggableContextSuite.scala b/modules/logging/structured/src/test/scala-2/tofu/logging/LoggableContextSuite.scala deleted file mode 100644 index a6fe5c726..000000000 --- a/modules/logging/structured/src/test/scala-2/tofu/logging/LoggableContextSuite.scala +++ /dev/null @@ -1,20 +0,0 @@ -package tofu.logging - -import tofu.compat.unused -import tofu.WithContext - -object LoggableContextSuite { - - def summonInstance[R: Loggable, F[_]: *[_] WithContext R](): Unit = { - LoggableContext.of[F].instance - () - } - - @unused - def summonInstanceUnambiguously[R1: Loggable, R2: Loggable, F[_]: *[_] WithContext R1: *[_] WithContext R2]() - : Unit = { - LoggableContext.of[F].instance[R1] - () - } - -} diff --git a/modules/logging/structured/src/test/scala-2/tofu/logging/LogTreeSuite.scala b/modules/logging/structured/src/test/scala/tofu/logging/LogTreeSuite.scala similarity index 94% rename from modules/logging/structured/src/test/scala-2/tofu/logging/LogTreeSuite.scala rename to modules/logging/structured/src/test/scala/tofu/logging/LogTreeSuite.scala index 89525b82c..3be2138fc 100644 --- a/modules/logging/structured/src/test/scala-2/tofu/logging/LogTreeSuite.scala +++ b/modules/logging/structured/src/test/scala/tofu/logging/LogTreeSuite.scala @@ -2,8 +2,8 @@ package tofu.logging import cats.syntax.semigroup._ import org.scalatest.funsuite.AnyFunSuite -import tofu.logging.{LogTree, TethysBuilder} import tofu.syntax.logRenderer._ + class LogTreeSuite extends AnyFunSuite { case class Data(field1: String, field2: Int) diff --git a/modules/logging/structured/src/test/scala/tofu/logging/LoggableContextSuite.scala b/modules/logging/structured/src/test/scala/tofu/logging/LoggableContextSuite.scala new file mode 100644 index 000000000..c5810560f --- /dev/null +++ b/modules/logging/structured/src/test/scala/tofu/logging/LoggableContextSuite.scala @@ -0,0 +1,23 @@ +package tofu.logging + +import tofu.compat.unused +import tofu.WithContext + +object LoggableContextSuite { + + def summonInstance[R: Loggable, F[_]: ({ type L[x[_]] = WithContext[x, R] })#L](): Unit = { + LoggableContext.of[F].instance + () + } + + @unused + def summonInstanceUnambiguously[ + R1: Loggable, + R2: Loggable, + F[_]: ({ type L[x[_]] = WithContext[x, R1] })#L: ({ type L[x[_]] = WithContext[x, R2] })#L + ](): Unit = { + LoggableContext.of[F].instance[R1] + () + } + +} diff --git a/modules/logging/structured/src/test/scala-2/tofu/logging/LoggableSuite.scala b/modules/logging/structured/src/test/scala/tofu/logging/LoggableSuite.scala similarity index 100% rename from modules/logging/structured/src/test/scala-2/tofu/logging/LoggableSuite.scala rename to modules/logging/structured/src/test/scala/tofu/logging/LoggableSuite.scala diff --git a/modules/logging/structured/src/test/scala-2/tofu/logging/LoggingSuite.scala b/modules/logging/structured/src/test/scala/tofu/logging/LoggingSuite.scala similarity index 98% rename from modules/logging/structured/src/test/scala-2/tofu/logging/LoggingSuite.scala rename to modules/logging/structured/src/test/scala/tofu/logging/LoggingSuite.scala index 2a23dedee..22ea9cd54 100644 --- a/modules/logging/structured/src/test/scala-2/tofu/logging/LoggingSuite.scala +++ b/modules/logging/structured/src/test/scala/tofu/logging/LoggingSuite.scala @@ -97,7 +97,7 @@ object LoggingSuite { val exception = new RuntimeException("ya oshibka") exception.setStackTrace(Array(new StackTraceElement("test1", "test2", "test3", 1337))) - class Exprs[F[_]: ServiceLogging[*[_], LoggingSuite]] { + class Exprs[F[_]: ({ type L[x[_]] = ServiceLogging[x, LoggingSuite] })#L] { val hello: F[Unit] = warn"hello" diff --git a/modules/logging/structured/src/test/scala-2/tofu/logging/NamedLoggableCompositionSuite.scala b/modules/logging/structured/src/test/scala/tofu/logging/NamedLoggableCompositionSuite.scala similarity index 100% rename from modules/logging/structured/src/test/scala-2/tofu/logging/NamedLoggableCompositionSuite.scala rename to modules/logging/structured/src/test/scala/tofu/logging/NamedLoggableCompositionSuite.scala diff --git a/modules/logging/structured/src/test/scala-2/tofu/logging/location/LocationSyntaxSuite.scala b/modules/logging/structured/src/test/scala/tofu/logging/location/LocationSyntaxSuite.scala similarity index 82% rename from modules/logging/structured/src/test/scala-2/tofu/logging/location/LocationSyntaxSuite.scala rename to modules/logging/structured/src/test/scala/tofu/logging/location/LocationSyntaxSuite.scala index ca0d569e2..d9ef8c544 100644 --- a/modules/logging/structured/src/test/scala-2/tofu/logging/location/LocationSyntaxSuite.scala +++ b/modules/logging/structured/src/test/scala/tofu/logging/location/LocationSyntaxSuite.scala @@ -7,8 +7,8 @@ import org.scalatest.flatspec.AnyFlatSpec import tofu.logging.{LoggedValue, Logging, Logs} import tofu.syntax.location.logging._ -object WriterLogs extends Logs[Id, Writer[List[String], *]] { - override def byName(name: String): Id[Logging[Writer[List[String], *]]] = new Logging[Writer[List[String], *]] { +object WriterLogs extends Logs[Id, Writer[List[String], _]] { + def byName(name: String): Id[Logging[Writer[List[String], _]]] = new Logging[Writer[List[String], _]] { override def write(level: Logging.Level, message: String, values: LoggedValue*): Writer[List[String], Unit] = Writer.tell(s"${level.toString.toUpperCase} | $message" :: values.map(_.toString).toList) } @@ -16,7 +16,7 @@ object WriterLogs extends Logs[Id, Writer[List[String], *]] { class TestService { type Run[A] = Writer[List[String], A] - implicit val logger: Logging[Writer[List[String], *]] = WriterLogs.byName("TestLogger") + implicit val logger: Logging[Writer[List[String], _]] = WriterLogs.byName("TestLogger") def sayHello(name: String): Run[String] = for { @@ -48,12 +48,12 @@ class LocationSyntaxSuite extends AnyFlatSpec { "Бублик the good dog", "tofu.logging.location.TestService.sayHello@(LocationSyntaxSuite.scala:23)", "INFO | Yes, I did it, I said hello!", - "tofu.logging.location.TestService.sayHello.23@(LocationSyntaxSuite.scala:25)", + "tofu.logging.location.TestService.sayHello@(LocationSyntaxSuite.scala:25)", "ERROR | I don't want to say goodbye to {}", "Бублик", "tofu.logging.location.TestService.sayGoodbye@(LocationSyntaxSuite.scala:30)", "INFO | Let the stars shine through", - "tofu.logging.location.TestService.sayGoodbye.30@(LocationSyntaxSuite.scala:32)" + "tofu.logging.location.TestService.sayGoodbye@(LocationSyntaxSuite.scala:32)" ) == log ) } diff --git a/modules/util/config/src/main/scala-2/tofu/config/Configurable.scala b/modules/util/config/src/main/scala-2/tofu/config/Configurable.scala index ca31eb8d7..3e39c6c13 100644 --- a/modules/util/config/src/main/scala-2/tofu/config/Configurable.scala +++ b/modules/util/config/src/main/scala-2/tofu/config/Configurable.scala @@ -15,7 +15,7 @@ import cats.syntax.option._ import cats.syntax.parallel._ import cats.syntax.monoid._ import cats.syntax.traverse._ -import magnolia.{CaseClass, Magnolia, SealedTrait} +import magnolia1.{CaseClass, Magnolia, SealedTrait} import syntax.context._ import syntax.handle._ import tofu.config.ConfigError.{BadNumber, BadString, BadType, Invalid, MultipleVariants, NoVariantFound} @@ -184,7 +184,7 @@ trait BaseGetters { self: Configurable.type => trait MagnoliaDerivation extends Derivation[Configurable] { type Typeclass[T] = Configurable[T] - def combine[T](ctx: CaseClass[Configurable, T]): Configurable[T] = + def join[T](ctx: CaseClass[Configurable, T]): Configurable[T] = if (ctx.isObject) new SingletonConfigurable(ctx.typeName.short, ctx.construct(_ => ())) else new Configurable[T] { @@ -202,7 +202,7 @@ trait MagnoliaDerivation extends Derivation[Configurable] { } } - def dispatch[T](ctx: SealedTrait[Configurable, T]): Configurable[T] = + def split[T](ctx: SealedTrait[Configurable, T]): Configurable[T] = ctx.subtypes.toList.map(_.typeclass).traverse[Option, Map[String, T]] { case en: EnumConfigurable[_] => Some(en.nameMap) case _ => None diff --git a/modules/util/config/src/main/scala-2/tofu/data/instances/order.scala b/modules/util/config/src/main/scala-2/tofu/data/instances/order.scala index 740ae4a25..a1203e801 100644 --- a/modules/util/config/src/main/scala-2/tofu/data/instances/order.scala +++ b/modules/util/config/src/main/scala-2/tofu/data/instances/order.scala @@ -1,11 +1,11 @@ package tofu.data.instances import cats.Order -import magnolia.{CaseClass, Magnolia, SealedTrait} +import magnolia1.{CaseClass, Magnolia, SealedTrait} object order { type Typeclass[A] = Order[A] - def combine[T](ctx: CaseClass[Order, T]): Order[T] = (x: T, y: T) => { + def join[T](ctx: CaseClass[Order, T]): Order[T] = (x: T, y: T) => { val it = ctx.parameters.iterator def go(): Int = if (it.hasNext) { @@ -17,7 +17,7 @@ object order { go() } - def dispatch[T](ctx: SealedTrait[Order, T]): Order[T] = + def split[T](ctx: SealedTrait[Order, T]): Order[T] = (x: T, y: T) => { val it = ctx.subtypes.iterator def go(): Int = diff --git a/project/Dependencies.scala b/project/Dependencies.scala index e14434336..cb61e62d7 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -14,7 +14,7 @@ object Dependencies { val circe = "0.14.5" - val tethys = "0.26.0" + val tethys = "0.28.0" val cats = "2.9.0" @@ -42,7 +42,9 @@ object Dependencies { val scalatest = "3.2.16" - val magnolia = "0.17.0" + val magnolia2 = "1.1.6" + + val magnolia3 = "1.3.4" val typesafeConfig = "1.4.2" @@ -93,57 +95,58 @@ object Dependencies { ExclusionRule("org.typelevel", "cats-effect_2.13"), ExclusionRule("org.typelevel", "cats-effect_2.12") ) - val catsCore = "org.typelevel" %% "cats-core" % Version.cats - val catsFree = "org.typelevel" %% "cats-free" % Version.cats - val catsMtl = "org.typelevel" %% "cats-mtl" % Version.catsMtl - val alleycats = "org.typelevel" %% "alleycats-core" % Version.cats - val catsEffect2 = "org.typelevel" %% "cats-effect" % Version.catsEffect2 - val catsEffect3 = "org.typelevel" %% "cats-effect" % Version.catsEffect3 - val monix = "io.monix" %% "monix" % Version.monix excludeAll (noCatsEffect: _*) - val logback = "ch.qos.logback" % "logback-classic" % Version.logback - val slf4j = "org.slf4j" % "slf4j-api" % Version.slf4j % Provided - val circeCore = "io.circe" %% "circe-core" % Version.circe excludeAll (noCatsCore: _*) - val circeJava8 = "io.circe" %% "circe-java8" % Version.circe excludeAll (noCatsCore: _*) - val circeDerivation = "io.circe" %% "circe-derivation" % Version.circe excludeAll (noCatsCore: _*) - val magnolia = "com.propensive" %% "magnolia" % Version.magnolia - val derevo = "tf.tofu" %% "derevo-core" % Version.derevo - val derevoCirce = "tf.tofu" %% "derevo-circe" % Version.derevo - val derevoTagless = "tf.tofu" %% "derevo-cats-tagless" % Version.derevo - val enumeratum = "com.beachape" %% "enumeratum" % Version.enumeratum - val fs2 = "co.fs2" %% "fs2-core" % Version.fs2 - val fs2CE3 = "co.fs2" %% "fs2-core" % Version.fs2CE3 - val tethys = "com.tethys-json" %% "tethys-core" % Version.tethys - val tethysJackson = "com.tethys-json" %% "tethys-jackson" % Version.tethys - val catsTaglessMacros = "org.typelevel" %% "cats-tagless-macros" % Version.catsTagless - val catsTaglessCore = "org.typelevel" %% "cats-tagless-core" % Version.catsTagless - val typesafeConfig = "com.typesafe" % "config" % Version.typesafeConfig - val zio = "dev.zio" %% "zio" % Version.zio - val zio2 = "dev.zio" %% "zio" % Version.zio2 - val zio2Test = "dev.zio" %% "zio-test" % Version.zio2 % Test - val zio2TestSbt = "dev.zio" %% "zio-test-sbt" % Version.zio2 % Test - val zioCats = "dev.zio" %% "zio-interop-cats" % Version.zioCats - val zio2Cats = "dev.zio" %% "zio-interop-cats" % Version.zio2Cats - val scalatest = "org.scalatest" %% "scalatest" % Version.scalatest % Test - val shapeless = "com.chuusai" %% "shapeless" % Version.shapeless - val refined = "eu.timepit" %% "refined" % Version.refined - val doobieCore = "org.tpolecat" %% "doobie-core" % Version.doobie - val doobieH2 = "org.tpolecat" %% "doobie-h2" % Version.doobie - val doobieCoreCE3 = "org.tpolecat" %% "doobie-core" % Version.doobieCE3 - val doobieH2CE3 = "org.tpolecat" %% "doobie-h2" % Version.doobieCE3 - val collectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % Version.collectionCompat - val log4CatsLegacy = "org.typelevel" %% "log4cats-core" % Version.log4CatsLegacy - val log4Cats = "org.typelevel" %% "log4cats-core" % Version.log4Cats - val logstashLogback = "net.logstash.logback" % "logstash-logback-encoder" % Version.logstashLogback - val groovy = "org.codehaus.groovy" % "groovy" % Version.groovy + val catsCore = "org.typelevel" %% "cats-core" % Version.cats + val catsFree = "org.typelevel" %% "cats-free" % Version.cats + val catsMtl = "org.typelevel" %% "cats-mtl" % Version.catsMtl + val alleycats = "org.typelevel" %% "alleycats-core" % Version.cats + val catsEffect2 = "org.typelevel" %% "cats-effect" % Version.catsEffect2 + val catsEffect3 = "org.typelevel" %% "cats-effect" % Version.catsEffect3 + val monix = "io.monix" %% "monix" % Version.monix excludeAll (noCatsEffect: _*) + val logback = "ch.qos.logback" % "logback-classic" % Version.logback + val slf4j = "org.slf4j" % "slf4j-api" % Version.slf4j % Provided + val circeCore = "io.circe" %% "circe-core" % Version.circe excludeAll (noCatsCore: _*) + val circeJava8 = "io.circe" %% "circe-java8" % Version.circe excludeAll (noCatsCore: _*) + val circeDerivation = "io.circe" %% "circe-derivation" % Version.circe excludeAll (noCatsCore: _*) + val magnolia2 = "com.softwaremill.magnolia1_2" %% "magnolia" % Version.magnolia2 + val magnolia3 = "com.softwaremill.magnolia1_3" %% "magnolia" % Version.magnolia3 + val derevo = "tf.tofu" %% "derevo-core" % Version.derevo + val derevoCirce = "tf.tofu" %% "derevo-circe" % Version.derevo + val derevoTagless = "tf.tofu" %% "derevo-cats-tagless" % Version.derevo + val enumeratum = "com.beachape" %% "enumeratum" % Version.enumeratum + val fs2 = "co.fs2" %% "fs2-core" % Version.fs2 + val fs2CE3 = "co.fs2" %% "fs2-core" % Version.fs2CE3 + val tethys = "com.tethys-json" %% "tethys-core" % Version.tethys + val tethysJackson = "com.tethys-json" %% "tethys-jackson213" % Version.tethys + val catsTaglessMacros = "org.typelevel" %% "cats-tagless-macros" % Version.catsTagless + val catsTaglessCore = "org.typelevel" %% "cats-tagless-core" % Version.catsTagless + val typesafeConfig = "com.typesafe" % "config" % Version.typesafeConfig + val zio = "dev.zio" %% "zio" % Version.zio + val zio2 = "dev.zio" %% "zio" % Version.zio2 + val zio2Test = "dev.zio" %% "zio-test" % Version.zio2 % Test + val zio2TestSbt = "dev.zio" %% "zio-test-sbt" % Version.zio2 % Test + val zioCats = "dev.zio" %% "zio-interop-cats" % Version.zioCats + val zio2Cats = "dev.zio" %% "zio-interop-cats" % Version.zio2Cats + val scalatest = "org.scalatest" %% "scalatest" % Version.scalatest % Test + val shapeless = "com.chuusai" %% "shapeless" % Version.shapeless + val refined = "eu.timepit" %% "refined" % Version.refined + val doobieCore = "org.tpolecat" %% "doobie-core" % Version.doobie + val doobieH2 = "org.tpolecat" %% "doobie-h2" % Version.doobie + val doobieCoreCE3 = "org.tpolecat" %% "doobie-core" % Version.doobieCE3 + val doobieH2CE3 = "org.tpolecat" %% "doobie-h2" % Version.doobieCE3 + val collectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % Version.collectionCompat + val log4CatsLegacy = "org.typelevel" %% "log4cats-core" % Version.log4CatsLegacy + val log4Cats = "org.typelevel" %% "log4cats-core" % Version.log4Cats + val logstashLogback = "net.logstash.logback" % "logstash-logback-encoder" % Version.logstashLogback + val groovy = "org.codehaus.groovy" % "groovy" % Version.groovy val http4s = Seq("org.http4s" %% "http4s-dsl", "org.http4s" %% "http4s-circe", "org.http4s" %% "http4s-blaze-server").map( _ % Version.http4s ) - val glassCore = "tf.tofu" %% "glass-core" % Version.glass - val glassMacro = "tf.tofu" %% "glass-macro" % Version.glass + val glassCore = "tf.tofu" %% "glass-core" % Version.glass + val glassMacro = "tf.tofu" %% "glass-macro" % Version.glass // Compile-time only - val macroParadise = "org.scalamacros" % "paradise" % Version.macroParadise cross CrossVersion.patch - val kindProjector = "org.typelevel" %% "kind-projector" % Version.kindProjector cross CrossVersion.patch - val simulacrum = "org.typelevel" %% "simulacrum" % Version.simulacrum - val betterMonadicFor = "com.olegpy" %% "better-monadic-for" % Version.betterMonadicFor + val macroParadise = "org.scalamacros" % "paradise" % Version.macroParadise cross CrossVersion.patch + val kindProjector = "org.typelevel" %% "kind-projector" % Version.kindProjector cross CrossVersion.patch + val simulacrum = "org.typelevel" %% "simulacrum" % Version.simulacrum + val betterMonadicFor = "com.olegpy" %% "better-monadic-for" % Version.betterMonadicFor } From 2cd8fd35ca8ab31c04646144b27a073c99e6771a Mon Sep 17 00:00:00 2001 From: Vladislav Ugryumov Date: Wed, 3 Apr 2024 01:49:46 +0300 Subject: [PATCH 2/9] Remove explicit Seq imports. --- .../src/main/scala-2/tofu/internal/Interop.scala | 6 ++---- .../kernel/src/main/scala/tofu/common/Display.scala | 2 +- .../main/scala/tofu/logging/LoggableInstances.scala | 8 ++++---- .../tofu/logging/builder/LoggingBiMidBuilder.scala | 1 - .../tofu/logging/builder/LoggingMidBuilder.scala | 11 +++++------ .../main/scala/tofu/logging/impl/ArgsLoggable.scala | 2 -- .../scala/tofu/logging/impl/UniversalLogging.scala | 1 - 7 files changed, 12 insertions(+), 19 deletions(-) diff --git a/modules/kernel/src/main/scala-2/tofu/internal/Interop.scala b/modules/kernel/src/main/scala-2/tofu/internal/Interop.scala index b5b1cc6eb..15d2d1b9e 100644 --- a/modules/kernel/src/main/scala-2/tofu/internal/Interop.scala +++ b/modules/kernel/src/main/scala-2/tofu/internal/Interop.scala @@ -1,5 +1,5 @@ package tofu.internal -import scala.collection + import scala.reflect.macros._ class Interop(val c: blackbox.Context) { @@ -10,9 +10,7 @@ class Interop(val c: blackbox.Context) { protected def tc[F[_]](implicit wttu: WTTU[F]) = wttu.tpe.typeConstructor protected def t[A](implicit wttu: WTT[A]) = wttu.tpe - protected def delegateParamTree[N]( - ps: collection.Seq[collection.Seq[Tree]] - )(ts: collection.Seq[Type])(implicit N: WTT[N]): Tree = { + protected def delegateParamTree[N](ps: Seq[Seq[Tree]])(ts: Seq[Type])(implicit N: WTT[N]): Tree = { val s = N.tpe.decls.head.asTerm.name.decodedName.toString val exp = c.parse(s) diff --git a/modules/kernel/src/main/scala/tofu/common/Display.scala b/modules/kernel/src/main/scala/tofu/common/Display.scala index ef2fcfe25..d8afdcc77 100644 --- a/modules/kernel/src/main/scala/tofu/common/Display.scala +++ b/modules/kernel/src/main/scala/tofu/common/Display.scala @@ -1,7 +1,7 @@ package tofu.common import cats.{Eval, Show} import java.util.UUID -import scala.collection.immutable.{BitSet, Queue, Seq, SortedMap, SortedSet} +import scala.collection.immutable.{BitSet, Queue, SortedMap, SortedSet} import scala.concurrent.duration.Duration import scala.util.Try diff --git a/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala index 69dd4eeb4..96c15b5f8 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala @@ -4,7 +4,7 @@ import java.time.{Instant, LocalDate, LocalDateTime, OffsetDateTime, ZonedDateTi import java.util.UUID import scala.collection.immutable.SortedSet -import scala.collection.{immutable, mutable} +import scala.collection.mutable.Buffer import scala.concurrent.duration.FiniteDuration import alleycats.std.iterable._ @@ -121,14 +121,14 @@ class LoggableInstances { private[this] def fldLoggable[T[x]: Foldable, A](implicit A: Loggable[A]): Loggable[T[A]] = new SubLoggable[T[A]] { def putValue[I, V, R, M](ta: T[A], v: V)(implicit r: LogRenderer[I, V, R, M]): M = { - val arr = ta.foldLeft(mutable.Buffer.newBuilder[A])(_ += _).result() + val arr = ta.foldLeft(Buffer.newBuilder[A])(_ += _).result() v.list(arr.size)((v, idx) => A.putValue(arr(idx), v)) } override def putMaskedValue[I, V, R, S](ta: T[A], v: V)( f: String => String )(implicit r: LogRenderer[I, V, R, S]): S = { - val arr = ta.foldLeft(mutable.Buffer.newBuilder[A])(_ += _).result() + val arr = ta.foldLeft(Buffer.newBuilder[A])(_ += _).result() v.list(arr.size)((v, idx) => A.putMaskedValue(arr(idx), v)(f)) } @@ -139,7 +139,7 @@ class LoggableInstances { } final implicit def seqLoggable[A: Loggable]: Loggable[collection.Seq[A]] = fldLoggable[Iterable, A].narrow - final implicit def immutableSeqLoggable[A: Loggable]: Loggable[immutable.Seq[A]] = + final implicit def immutableSeqLoggable[A: Loggable]: Loggable[Seq[A]] = fldLoggable[Iterable, A].narrow final implicit def listLoggable[A: Loggable]: Loggable[List[A]] = fldLoggable[List, A] diff --git a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala index 5be53bff0..b6591c4b8 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala @@ -7,7 +7,6 @@ import tofu.logging.bi.LoggingBiMid import tofu.logging.impl.ArgsLoggable import tofu.syntax.bindInv._ -import scala.collection.immutable.Seq import scala.collection.mutable.Buffer import scala.reflect.ClassTag diff --git a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala index 0e480d9b3..174fa4cb8 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala @@ -1,8 +1,7 @@ package tofu.logging package builder -import scala.collection.immutable.Seq -import scala.collection.mutable +import scala.collection.mutable.Buffer import scala.reflect.ClassTag import tofu.syntax.monadic._ import cats.Monad @@ -46,7 +45,7 @@ trait LoggingMidBuilder extends Builder[LoggingMid] { protected class MethodImpl[U[f[_]], Res: Loggable]( cls: Class[?], method: String, - args: mutable.Buffer[(String, LoggedValue)] + args: Buffer[(String, LoggedValue)] ) extends Method[U, Res, LoggingMid] { def arg[A: Loggable](name: String, a: A): this.type = { args += (name -> a) @@ -62,7 +61,7 @@ trait LoggingMidBuilder extends Builder[LoggingMid] { } protected class PreparedImpl[U[f[_]]](cls: Class[?]) extends Prepared[U, LoggingMid] { - def start[Res: Loggable](method: String): MethodImpl[U, Res] = new MethodImpl(cls, method, mutable.Buffer()) + def start[Res: Loggable](method: String): MethodImpl[U, Res] = new MethodImpl(cls, method, Buffer()) } } @@ -111,7 +110,7 @@ trait LoggingErrMidBuilder[E] extends LoggingMidBuilder with Builder[LoggingErrM protected class MethodErrImpl[U[f[_]], Res: Loggable]( cls: Class[?], method: String, - args: mutable.Buffer[(String, LoggedValue)] + args: Buffer[(String, LoggedValue)] ) extends MethodImpl[U, Res](cls, method, args) with Method[U, Res, LoggingErrMid[E, _]] { override def result: LoggingErrMid[E, Res] = new LoggingErrMid[E, Res] { private[this] val argSeq = args.toSeq @@ -125,7 +124,7 @@ trait LoggingErrMidBuilder[E] extends LoggingMidBuilder with Builder[LoggingErrM class PreparedErr[U[f[_]]](cls: Class[?]) extends super.PreparedImpl[U](cls) with Prepared[U, LoggingErrMid[E, _]] { override def start[Res: Loggable](method: String): MethodErrImpl[U, Res] = - new MethodErrImpl(cls, method, mutable.Buffer()) + new MethodErrImpl(cls, method, Buffer()) } } diff --git a/modules/logging/structured/src/main/scala/tofu/logging/impl/ArgsLoggable.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/ArgsLoggable.scala index 4e929d96a..c368eb656 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/impl/ArgsLoggable.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/ArgsLoggable.scala @@ -2,8 +2,6 @@ package tofu.logging.impl import tofu.logging.{LogRenderer, LoggedValue} -import scala.collection.immutable.Seq - class ArgsLoggable(values: Seq[(String, LoggedValue)]) extends LoggedValue { override def shortName: String = "arguments" diff --git a/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalLogging.scala b/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalLogging.scala index 9223186f4..c57f20077 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalLogging.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/impl/UniversalLogging.scala @@ -6,7 +6,6 @@ import org.slf4j.{Logger, LoggerFactory, Marker} import tofu.logging.Logging.{Debug, Error, Info, Trace, Warn} import tofu.{Delay, WithContext} import scala.annotation.nowarn -import scala.collection.immutable.Seq @nowarn("msg=a type was inferred to be `Object`") //cat=lint-infer-any filter does not work for Scala 3 object UniversalLogging { From 3f821663160c1727a29aee81eac9625ddaae9e65 Mon Sep 17 00:00:00 2001 From: Vladislav Ugryumov Date: Wed, 3 Apr 2024 02:05:12 +0300 Subject: [PATCH 3/9] Fix some migration syntax issues. --- .../tofu/control/impl/BindInstanceChain.scala | 2 +- .../scala/tofu/higherKind/MonoidalK.scala | 4 +-- .../src/main/scala/tofu/higherKind/Post.scala | 2 +- .../src/main/scala/tofu/higherKind/Pre.scala | 2 +- .../tofu/higherKind/bi/BiRepresentableK.scala | 2 +- .../control/CatsInstancesFromBindSuite.scala | 4 +-- .../kernel/src/main/scala/tofu/Context.scala | 12 ++++----- .../kernel/src/main/scala/tofu/Errors.scala | 10 +++---- .../kernel/src/main/scala/tofu/Perform.scala | 4 +-- .../kernel/src/main/scala/tofu/Scoped.scala | 4 +-- .../src/main/scala/tofu/WithProvide.scala | 6 ++--- .../kernel/src/main/scala/tofu/WithRun.scala | 6 ++--- .../src/main/scala/tofu/concurrent/Atom.scala | 10 +++---- .../src/main/scala/tofu/concurrent/Exit.scala | 6 ++--- .../main/scala/tofu/control/Selective.scala | 8 +++--- .../control/impl/SelectiveInstances.scala | 12 ++++----- .../src/main/scala/tofu/data/Calc.scala | 4 +-- .../src/main/scala/tofu/data/Embedded.scala | 26 +++++++++---------- .../src/main/scala/tofu/data/Flux.scala | 18 ++++++------- .../scala/tofu/data/calc/CalcMInstances.scala | 26 +++++++++---------- .../src/main/scala/tofu/data/calc/CalcT.scala | 2 +- .../scala/tofu/data/calc/Translator.scala | 2 +- .../src/main/scala/tofu/data/data.scala | 2 +- .../scala/tofu/errorInstances/package.scala | 6 ++--- .../tofu/internal/instances/perform.scala | 12 ++++----- .../src/main/scala/tofu/lift/Unlift.scala | 6 ++--- .../test/scala/tofu/ContextSummonSuite.scala | 18 ++++++------- .../main/scala/tofu/logging/LoggingMid.scala | 2 +- .../internal/LogsInvariantSyntax.scala | 4 +-- 29 files changed, 111 insertions(+), 111 deletions(-) diff --git a/modules/kernel/higherKind/src/main/scala/tofu/control/impl/BindInstanceChain.scala b/modules/kernel/higherKind/src/main/scala/tofu/control/impl/BindInstanceChain.scala index fa7442fb5..fdf41f669 100644 --- a/modules/kernel/higherKind/src/main/scala/tofu/control/impl/BindInstanceChain.scala +++ b/modules/kernel/higherKind/src/main/scala/tofu/control/impl/BindInstanceChain.scala @@ -38,7 +38,7 @@ trait BindInstanceChain[TC[f[_, _]] >: Bind[f]] { override def handle[E, X, A](fa: Either[E, A], h: E => A): Either[X, A] = Right(fa.fold(h, identity)) - override def monad[E]: Monad[Either[E, *]] = implicitly + override def monad[E]: Monad[Either[E, _]] = implicitly override def bifunctor: Bifunctor[Either] = implicitly } diff --git a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/MonoidalK.scala b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/MonoidalK.scala index ad5d5a317..05b8ef1f9 100644 --- a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/MonoidalK.scala +++ b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/MonoidalK.scala @@ -12,13 +12,13 @@ import tofu.internal.EffectCompHK trait MonoidalK[U[_[_]]] extends PureK[U] with ApplyK[U] { def zipWith2K[F[_], G[_], H[_]](af: U[F], ag: U[G])(f2: Function2K[F, G, H]): U[H] - override def map2K[F[_], G[_], H[_]](af: U[F], ag: U[G])(f: Tuple2K[F, G, *] ~> H): U[H] = + override def map2K[F[_], G[_], H[_]](af: U[F], ag: U[G])(f: Tuple2K[F, G, _] ~> H): U[H] = zipWith2K(af, ag)(Function2K.untupled(f)) override def mapK[F[_], G[_]](af: U[F])(fk: F ~> G): U[G] = zipWith2K[F, UnitK, G](af, unitK)(Function2K[F, UnitK]((f, _) => fk(f))) - override def productK[F[_], G[_]](af: U[F], ag: U[G]): U[Tuple2K[F, G, *]] = + override def productK[F[_], G[_]](af: U[F], ag: U[G]): U[Tuple2K[F, G, _]] = zipWith2K(af, ag)(Function2K[F, G]((f, g) => Tuple2K(f, g))) } diff --git a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Post.scala b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Post.scala index 69a9c98eb..613cd772a 100644 --- a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Post.scala +++ b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Post.scala @@ -6,7 +6,7 @@ import cats.{Applicative, Apply, FlatMap, Monoid, MonoidK, Semigroup, SemigroupK import tofu.syntax.funk.funK import tofu.syntax.monadic.* -/** A function `[F[_], A] =>> A => F[Unit]` An algebra `U[Post[F, *]]` is an algebra which translates all actions to `A +/** A function `[F[_], A] =>> A => F[Unit]` An algebra `U[Post[F, _]]` is an algebra which translates all actions to `A * \=> F[Unit]`. This is useful to represent actions succeeding main logic. */ trait Post[F[_], A] { diff --git a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Pre.scala b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Pre.scala index 35a71b3a5..07b635190 100644 --- a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Pre.scala +++ b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/Pre.scala @@ -6,7 +6,7 @@ import cats.{Applicative, Apply, Monoid, MonoidK, Semigroup, SemigroupK, ~>} import tofu.syntax.funk.funK import tofu.syntax.monadic.* -/** Newtype for `[F[_], A] =>> F[Unit]`. An algebra `U[Pre[F, *]]` is an algebra which translates all actions to +/** Newtype for `[F[_], A] =>> F[Unit]`. An algebra `U[Pre[F, _]]` is an algebra which translates all actions to * `F[Unit]`. This is useful to represent actions preceding main logic. */ object Pre extends PreInstances { diff --git a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/bi/BiRepresentableK.scala b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/bi/BiRepresentableK.scala index b7d999836..4bfa1393b 100644 --- a/modules/kernel/higherKind/src/main/scala/tofu/higherKind/bi/BiRepresentableK.scala +++ b/modules/kernel/higherKind/src/main/scala/tofu/higherKind/bi/BiRepresentableK.scala @@ -4,7 +4,7 @@ import tofu.control.Bind import tofu.higherKind.bi.RepresentableB.Tab trait RepresentableB[U[f[_, _]]] extends MonoidalBK[U] with EmbedBK[U] { - def bitabulate[F[_, _]](repr: RepBK[U, *, *] FunBK F): U[F] + def bitabulate[F[_, _]](repr: RepBK[U, _, _] FunBK F): U[F] final def tab[F[_, _]]: Tab[U, F] = new Tab(this) diff --git a/modules/kernel/higherKind/src/test/scala/tofu/control/CatsInstancesFromBindSuite.scala b/modules/kernel/higherKind/src/test/scala/tofu/control/CatsInstancesFromBindSuite.scala index 603f15f39..6bd072a2c 100644 --- a/modules/kernel/higherKind/src/test/scala/tofu/control/CatsInstancesFromBindSuite.scala +++ b/modules/kernel/higherKind/src/test/scala/tofu/control/CatsInstancesFromBindSuite.scala @@ -5,8 +5,8 @@ import tofu.instances.bind._ class CatsInstancesFromBindSuite { def summonBindInstances[F[+_, +_]](implicit bind: Bind[F]): Unit = { - requireApplicative[F[Throwable, *]] - requireFlatMap[F[Nothing, *]] + requireApplicative[F[Throwable, _]] + requireFlatMap[F[Nothing, _]] } def requireApplicative[F[_]](implicit applicative: Applicative[F]): Unit = () diff --git a/modules/kernel/src/main/scala/tofu/Context.scala b/modules/kernel/src/main/scala/tofu/Context.scala index 1baaa0723..1a505ec2f 100644 --- a/modules/kernel/src/main/scala/tofu/Context.scala +++ b/modules/kernel/src/main/scala/tofu/Context.scala @@ -169,7 +169,7 @@ object Local { * that can use `F[Ctx]` inside. * * @tparam F - * context-aware effect e.g.`ReaderT[Lower, Ctx, *]` + * context-aware effect e.g.`ReaderT[Lower, Ctx, _]` */ @deprecated("Migrate to With* typeclasses", "0.10.3") trait Provide[F[_]] extends ContextBase { @@ -205,10 +205,10 @@ trait Provide[F[_]] extends ContextBase { * * @example * {{{ trait ProcessHandler[G[_]] { def mapK[M[_]](fk: G ~> M): ProcessHandler[M] = ??? //...other methods } type - * WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] val contextualProcessHandler: ProcessHandler[IO WithMyContext *] = + * WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] val contextualProcessHandler: ProcessHandler[IO WithMyContext _] = * ??? * - * val processHandler: ProcessHandler[IO] = processHandler.mapK( WithProvide[IO WithMyContext *, IO, + * val processHandler: ProcessHandler[IO] = processHandler.mapK( WithProvide[IO WithMyContext _, IO, * MyCtx].runContextK ) }}} */ def runContextK(ctx: Ctx): F ~> Lower = funK[F, Lower](a => runContext(a)(ctx)) @@ -244,7 +244,7 @@ object Provide { /** Combination of [[Local]] and [[Provide]] * * @tparam F - * context-aware effect e.g.`ReaderT[Lower, Ctx, *]` + * context-aware effect e.g.`ReaderT[Lower, Ctx, _]` */ @deprecated("Migrate to With* typeclasses", "0.10.3") trait RunContext[F[_]] extends Local[F] with Provide[F] { @@ -256,9 +256,9 @@ trait RunContext[F[_]] extends Local[F] with Provide[F] { * * type WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] * - * val processHandler: ProcessHandler[IO WithMyContext *] = ??? + * val processHandler: ProcessHandler[IO WithMyContext _] = ??? * - * val contextualHandler: IO WithMyContext ProcessHandler[IO] = processHandler.mapK( WithRun[WithMyContext[IO, *], + * val contextualHandler: IO WithMyContext ProcessHandler[IO] = processHandler.mapK( WithRun[WithMyContext[IO, _], * IO, MyCtx].unlift.map(fk => processHandler.mapK(fk)) ) //now it is able to process MyCtx but is wrapped in IO * WithMyContext * }}} * @return diff --git a/modules/kernel/src/main/scala/tofu/Errors.scala b/modules/kernel/src/main/scala/tofu/Errors.scala index c1b49397c..ae34dbf9b 100644 --- a/modules/kernel/src/main/scala/tofu/Errors.scala +++ b/modules/kernel/src/main/scala/tofu/Errors.scala @@ -130,8 +130,8 @@ object Errors extends DataEffectComp[Errors] { trait ErrorBase object ErrorBase extends ErrorsBaseInstances { - final implicit def readerTErrors[F[_], R, E](implicit F: Errors[F, E]): Errors[ReaderT[F, R, *], E] = - new Errors[ReaderT[F, R, *], E] { + final implicit def readerTErrors[F[_], R, E](implicit F: Errors[F, E]): Errors[ReaderT[F, R, _], E] = + new Errors[ReaderT[F, R, _], E] { def raise[A](err: E): ReaderT[F, R, A] = ReaderT.liftF(F.raise(err)) @@ -177,12 +177,12 @@ class ErrorsBaseInstances2 extends ErrorsBaseInstances3 { class ErrorsBaseInstances3 { - final implicit def eitherTIntance[F[_], E](implicit F: Monad[F]): ErrorsTo[EitherT[F, E, *], F, E] = + final implicit def eitherTIntance[F[_], E](implicit F: Monad[F]): ErrorsTo[EitherT[F, E, _], F, E] = new EitherTErrorsTo[F, E] - final implicit def optionTIntance[F[_]](implicit F: Monad[F]): ErrorsTo[OptionT[F, *], F, Unit] = + final implicit def optionTIntance[F[_]](implicit F: Monad[F]): ErrorsTo[OptionT[F, _], F, Unit] = new OptionTErrorsTo[F] - final implicit def eitherIntance[E]: ErrorsTo[Either[E, *], Id, E] = new EitherErrorsTo[E] + final implicit def eitherIntance[E]: ErrorsTo[Either[E, _], Id, E] = new EitherErrorsTo[E] final implicit val optionTIntance: ErrorsTo[Option, Id, Unit] = OptionErrorsTo } diff --git a/modules/kernel/src/main/scala/tofu/Perform.scala b/modules/kernel/src/main/scala/tofu/Perform.scala index 3851a4505..70d62d3f7 100644 --- a/modules/kernel/src/main/scala/tofu/Perform.scala +++ b/modules/kernel/src/main/scala/tofu/Perform.scala @@ -22,7 +22,7 @@ trait Performer[F[_], -Cont[_], Cancel] { } object Performer { - type OfExit[F[_], E] = Performer[F, PerformOf.ExitCont[E, *], Unit] + type OfExit[F[_], E] = Performer[F, PerformOf.ExitCont[E, _], Unit] implicit def contravariantK[F[_], Cancel]: ContravariantK[({ type L[x[_]] = Performer[F, x, Cancel] })#L] = new PerformerContravariantK[F, Cancel] @@ -49,7 +49,7 @@ object PerformVia extends PerformInstance with PerformInstance1 { trait PerformInstance1 { implicit def performReader[F[_]: Functor, Cont[_], R, Cancel](implicit RP: PerformVia[F, Cont, Cancel] - ): PerformVia[ReaderT[F, R, *], Cont, Cancel] = new PerformViaReader(RP) + ): PerformVia[ReaderT[F, R, _], Cont, Cancel] = new PerformViaReader(RP) } object PerformOf extends Effect2Comp[PerformOf] { diff --git a/modules/kernel/src/main/scala/tofu/Scoped.scala b/modules/kernel/src/main/scala/tofu/Scoped.scala index 2bcfe4666..99adeeb38 100644 --- a/modules/kernel/src/main/scala/tofu/Scoped.scala +++ b/modules/kernel/src/main/scala/tofu/Scoped.scala @@ -29,7 +29,7 @@ trait Scoped[Tag, F[_]] { final def tagged[NewTag]: Scoped[NewTag, F] = this.asInstanceOf[Scoped[NewTag, F]] - final def midPoint: Point[Mid[F, *]] = new Point[Mid[F, *]] { + final def midPoint: Point[Mid[F, _]] = new Point[Mid[F, _]] { def point[A]: Mid[F, A] = runScoped(_) } } @@ -78,7 +78,7 @@ object Scoped extends ScopedInstance with ScopedInstancesMacro { } /** helpful method to create middleware that executes all proceses in the given scope */ - def mid[Tag, U[_[_]], F[_]](implicit U: PureK[U], F: Scoped[Tag, F]): U[Mid[F, *]] = U.pureK(F.midPoint) + def mid[Tag, U[_[_]], F[_]](implicit U: PureK[U], F: Scoped[Tag, F]): U[Mid[F, _]] = U.pureK(F.midPoint) } trait ScopedExecute[Tag, F[_]] extends Scoped[Tag, F] { diff --git a/modules/kernel/src/main/scala/tofu/WithProvide.scala b/modules/kernel/src/main/scala/tofu/WithProvide.scala index d41c745bb..1179f171e 100644 --- a/modules/kernel/src/main/scala/tofu/WithProvide.scala +++ b/modules/kernel/src/main/scala/tofu/WithProvide.scala @@ -7,7 +7,7 @@ import tofu.syntax.funk.funK /** Synonym for [[Provide]] with explicit `C` as `Ctx` and `G` as `Lower` for better type inference * - * Can be seen as transformation `F[*] = C => G[*]` + * Can be seen as transformation `F[_] = C => G[_]` */ trait WithProvide[F[_], G[_], C] extends Provide[F] with Lift[G, F] { override type Lower[A] = G[A] @@ -40,10 +40,10 @@ trait WithProvide[F[_], G[_], C] extends Provide[F] with Lift[G, F] { * * @example * {{{ trait ProcessHandler[G[_]] { def mapK[M[_]](fk: G ~> M): ProcessHandler[M] = ??? //...other methods } type - * WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] val contextualProcessHandler: ProcessHandler[IO WithMyContext *] = + * WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] val contextualProcessHandler: ProcessHandler[IO WithMyContext _] = * ??? * - * val processHandler: ProcessHandler[IO] = processHandler.mapK( WithProvide[IO WithMyContext *, IO, + * val processHandler: ProcessHandler[IO] = processHandler.mapK( WithProvide[IO WithMyContext _, IO, * MyCtx].runContextK ) }}} */ override def runContextK(ctx: Ctx): F ~> Lower = funK[F, Lower](runContext(_)(ctx)) diff --git a/modules/kernel/src/main/scala/tofu/WithRun.scala b/modules/kernel/src/main/scala/tofu/WithRun.scala index 2348bfebf..6454b7cb6 100644 --- a/modules/kernel/src/main/scala/tofu/WithRun.scala +++ b/modules/kernel/src/main/scala/tofu/WithRun.scala @@ -8,7 +8,7 @@ import tofu.syntax.funk.funK /** Synonym for both [[RunContext]] and [[Unlift]] with explicit `C` as `Ctx` and `G` as `Lower` for better type * inference * - * Can be seen as transformation `F[*] = C => G[*]` + * Can be seen as transformation `F[_] = C => G[_]` */ trait WithRun[F[_], G[_], C] extends WithProvide[F, G, C] with WithLocal[F, C] with RunContext[F] with Unlift[G, F] { override type Ctx = C @@ -20,9 +20,9 @@ trait WithRun[F[_], G[_], C] extends WithProvide[F, G, C] with WithLocal[F, C] w * * type WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] * - * val processHandler: ProcessHandler[IO WithMyContext *] = ??? + * val processHandler: ProcessHandler[IO WithMyContext _] = ??? * - * val contextualHandler: IO WithMyContext ProcessHandler[IO] = processHandler.mapK( WithRun[WithMyContext[IO, *], + * val contextualHandler: IO WithMyContext ProcessHandler[IO] = processHandler.mapK( WithRun[WithMyContext[IO, _], * IO, MyCtx].unlift.map(fk => processHandler.mapK(fk)) ) //now it is able to process MyCtx but is wrapped in IO * WithMyContext * }}} * @return diff --git a/modules/kernel/src/main/scala/tofu/concurrent/Atom.scala b/modules/kernel/src/main/scala/tofu/concurrent/Atom.scala index 585c2c483..48e30e54f 100644 --- a/modules/kernel/src/main/scala/tofu/concurrent/Atom.scala +++ b/modules/kernel/src/main/scala/tofu/concurrent/Atom.scala @@ -62,9 +62,9 @@ object Atom extends AtomInstances { } } - def stateTAtom[F[_]: Applicative, A]: Atom[StateT[F, A, *], A] = StateTAtom() + def stateTAtom[F[_]: Applicative, A]: Atom[StateT[F, A, _], A] = StateTAtom() - private case class StateTAtom[F[_]: Applicative, A]() extends Atom[StateT[F, A, *], A] { + private case class StateTAtom[F[_]: Applicative, A]() extends Atom[StateT[F, A, _], A] { override def get: StateT[F, A, A] = StateT.get override def set(a: A): StateT[F, A, Unit] = StateT.set(a) override def getAndSet(a: A): StateT[F, A, A] = StateT(a1 => (a, a1).pure[F]) @@ -72,10 +72,10 @@ object Atom extends AtomInstances { override def modify[B](f: A => (A, B)): StateT[F, A, B] = StateT(a => f(a).pure[F]) } - def calcMAtom[F[+_, +_], R, S, E]: Atom[CalcM[F, R, S, S, E, *], S] = - calcMAtomAny.asInstanceOf[Atom[CalcM[F, R, S, S, E, *], S]] + def calcMAtom[F[+_, +_], R, S, E]: Atom[CalcM[F, R, S, S, E, _], S] = + calcMAtomAny.asInstanceOf[Atom[CalcM[F, R, S, S, E, _], S]] - private class CalcMAtom[F[+_, +_], R, S, E]() extends Atom[CalcM[F, R, S, S, E, *], S] { + private class CalcMAtom[F[+_, +_], R, S, E]() extends Atom[CalcM[F, R, S, S, E, _], S] { def get: CalcM[F, R, S, S, E, S] = CalcM.get def set(a: S): CalcM[F, R, S, S, E, Unit] = CalcM.set(a).void def getAndSet(a: S): CalcM[F, R, S, S, E, S] = CalcM.get[S] << CalcM.set(a) diff --git a/modules/kernel/src/main/scala/tofu/concurrent/Exit.scala b/modules/kernel/src/main/scala/tofu/concurrent/Exit.scala index 2773a49af..e6cc90543 100644 --- a/modules/kernel/src/main/scala/tofu/concurrent/Exit.scala +++ b/modules/kernel/src/main/scala/tofu/concurrent/Exit.scala @@ -40,7 +40,7 @@ object Exit { case util.Success(res) => Completed(res) } - private[this] object exitInstanceAny extends Traverse[Exit[Any, *]] with ApplicativeZip[Exit[Any, *]] { + private[this] object exitInstanceAny extends Traverse[Exit[Any, _]] with ApplicativeZip[Exit[Any, _]] { def traverse[G[_], A, B](fa: Exit[Any, A])(f: A => G[B])(implicit G: Applicative[G]): G[Exit[Any, B]] = fa match { case Canceled => G.pure(Canceled) @@ -78,8 +78,8 @@ object Exit { def pure[A](x: A): Exit[Any, A] = Completed(x) } - implicit def exitInstance[E]: Traverse[Exit[E, *]] with Applicative[Exit[E, *]] = - exitInstanceAny.asInstanceOf[Traverse[Exit[E, *]] with Applicative[Exit[E, *]]] + implicit def exitInstance[E]: Traverse[Exit[E, _]] with Applicative[Exit[E, _]] = + exitInstanceAny.asInstanceOf[Traverse[Exit[E, _]] with Applicative[Exit[E, _]]] object CanceledException extends InterruptedException } diff --git a/modules/kernel/src/main/scala/tofu/control/Selective.scala b/modules/kernel/src/main/scala/tofu/control/Selective.scala index c5dcf2d0a..742e1d0ef 100644 --- a/modules/kernel/src/main/scala/tofu/control/Selective.scala +++ b/modules/kernel/src/main/scala/tofu/control/Selective.scala @@ -43,9 +43,9 @@ trait SelectiveInstances extends SelectiveInstances2 { final implicit def selectiveOverMonad[F[_]: Monad]: SelectiveOverMonad[F] = new SelectiveOverMonad[F] } trait SelectiveInstances2 { - final implicit def selectiveOptionT[F[_]: Selective]: Selective[OptionT[F, *]] = new SelectiveOptionT[F] - final implicit def selectiveEitherT[F[_]: Selective, E]: Selective[EitherT[F, E, *]] = new SelectiveEitherT[F, E] - final implicit def selectiveReaderT[F[_]: Selective, R]: Selective[ReaderT[F, R, *]] = new SelectiveReaderT[F, R] - final implicit def selectiveWriterT[F[_]: Selective, W: Monoid]: Selective[WriterT[F, W, *]] = + final implicit def selectiveOptionT[F[_]: Selective]: Selective[OptionT[F, _]] = new SelectiveOptionT[F] + final implicit def selectiveEitherT[F[_]: Selective, E]: Selective[EitherT[F, E, _]] = new SelectiveEitherT[F, E] + final implicit def selectiveReaderT[F[_]: Selective, R]: Selective[ReaderT[F, R, _]] = new SelectiveReaderT[F, R] + final implicit def selectiveWriterT[F[_]: Selective, W: Monoid]: Selective[WriterT[F, W, _]] = new SelectiveWriterT[F, W] } diff --git a/modules/kernel/src/main/scala/tofu/control/impl/SelectiveInstances.scala b/modules/kernel/src/main/scala/tofu/control/impl/SelectiveInstances.scala index 1092c98a3..36332dec8 100644 --- a/modules/kernel/src/main/scala/tofu/control/impl/SelectiveInstances.scala +++ b/modules/kernel/src/main/scala/tofu/control/impl/SelectiveInstances.scala @@ -42,7 +42,7 @@ trait SelectiveWithMap[F[_]] extends Selective[F] { override def map[A, B](fa: F[A])(f: A => B): F[B] = smap(fa)(f) } -class SelectiveOptionT[F[_]](implicit F: Selective[F]) extends Selective[OptionT[F, *]] { +class SelectiveOptionT[F[_]](implicit F: Selective[F]) extends Selective[OptionT[F, _]] { def selectAp[A, B](fe: OptionT[F, Either[A, B]])(ff: => OptionT[F, A => B]): OptionT[F, B] = OptionT(F.selectAp(fe.value.map { case Some(Left(a)) => Left(a) @@ -59,7 +59,7 @@ class SelectiveOptionT[F[_]](implicit F: Selective[F]) extends Selective[OptionT def pure[A](x: A): OptionT[F, A] = OptionT.pure(x) } -class SelectiveEitherT[F[_], L](implicit F: Selective[F]) extends Selective[EitherT[F, L, *]] { +class SelectiveEitherT[F[_], L](implicit F: Selective[F]) extends Selective[EitherT[F, L, _]] { def selectAp[A, B](fe: EitherT[F, L, Either[A, B]])(ff: => EitherT[F, L, A => B]): EitherT[F, L, B] = EitherT(F.selectAp[A, Either[L, B]](fe.value.map { case Right(Left(a)) => Left(a) @@ -77,16 +77,16 @@ class SelectiveEitherT[F[_], L](implicit F: Selective[F]) extends Selective[Eith } class SelectiveReaderT[F[_], R](implicit FS: Selective[F]) - extends Selective[ReaderT[F, R, *]] with ApplicativeDelegate[ReaderT[F, R, *]] { - val F: Applicative[ReaderT[F, R, *]] = implicitly + extends Selective[ReaderT[F, R, _]] with ApplicativeDelegate[ReaderT[F, R, _]] { + val F: Applicative[ReaderT[F, R, _]] = implicitly def selectAp[A, B](fe: ReaderT[F, R, Either[A, B]])(ff: => ReaderT[F, R, A => B]): ReaderT[F, R, B] = ReaderT(r => FS.selectAp(fe.run(r))(ff.run(r))) } class SelectiveWriterT[F[_], W: Monoid](implicit FS: Selective[F]) - extends Selective[WriterT[F, W, *]] with ApplicativeDelegate[WriterT[F, W, *]] { - val F: Applicative[WriterT[F, W, *]] = implicitly + extends Selective[WriterT[F, W, _]] with ApplicativeDelegate[WriterT[F, W, _]] { + val F: Applicative[WriterT[F, W, _]] = implicitly def selectAp[A, B](fe: WriterT[F, W, Either[A, B]])(ff: => WriterT[F, W, A => B]): WriterT[F, W, B] = WriterT(FS.selectAp[(W, A), (W, B)](FS.map(fe.run) { diff --git a/modules/kernel/src/main/scala/tofu/data/Calc.scala b/modules/kernel/src/main/scala/tofu/data/Calc.scala index 3ca971d68..ed29241a8 100644 --- a/modules/kernel/src/main/scala/tofu/data/Calc.scala +++ b/modules/kernel/src/main/scala/tofu/data/Calc.scala @@ -163,8 +163,8 @@ object Calc { implicit def calcInstance[R, S, E]: CalcFunctorInstance[R, S, E] = new CalcFunctorInstance[R, S, E] class CalcFunctorInstance[R, S, E] - extends MonadError[Calc[R, S, S, E, *], E] with cats.Defer[Calc[R, S, S, E, *]] - with StackSafeMonad[Calc[R, S, S, E, *]] with Guarantee[Calc[R, S, S, E, *]] { + extends MonadError[Calc[R, S, S, E, _], E] with cats.Defer[Calc[R, S, S, E, _]] + with StackSafeMonad[Calc[R, S, S, E, _]] with Guarantee[Calc[R, S, S, E, _]] { def defer[A](fa: => Calc[R, S, S, E, A]): Calc[R, S, S, E, A] = Calc.defer(fa) def raiseError[A](e: E): Calc[R, S, S, E, A] = Calc.raise(e) def handleErrorWith[A](fa: Calc[R, S, S, E, A])(f: E => Calc[R, S, S, E, A]): Calc[R, S, S, E, A] = fa.handleWith(f) diff --git a/modules/kernel/src/main/scala/tofu/data/Embedded.scala b/modules/kernel/src/main/scala/tofu/data/Embedded.scala index 2fd3d17da..4d7fb01ac 100644 --- a/modules/kernel/src/main/scala/tofu/data/Embedded.scala +++ b/modules/kernel/src/main/scala/tofu/data/Embedded.scala @@ -30,14 +30,14 @@ trait ExceptTInstances extends ExceptTInstances1 { implicit def exceptTVeryParallel[G[+_], E](implicit G: Parallel[G], E: Semigroup[E] - ): Parallel.Aux[ExceptT[G, E, *], ExceptTPar[G.F, E, *]] = - new Parallel[ExceptT[G, E, *]] { + ): Parallel.Aux[ExceptT[G, E, _], ExceptTPar[G.F, E, _]] = + new Parallel[ExceptT[G, E, _]] { type F[A] = ExceptTPar[G.F, E, A] - @inline private def par1 = funk.funKFrom[ExceptT[G, E, *]](fx => toPar(G.parallel(fx.value))) + @inline private def par1 = funk.funKFrom[ExceptT[G, E, _]](fx => toPar(G.parallel(fx.value))) def parallel = par1 - def sequential = funk.funKFrom[ExceptTPar[G.F, E, *]](fx => Embedded(G.sequential(fromPar(fx)))) + def sequential = funk.funKFrom[ExceptTPar[G.F, E, _]](fx => Embedded(G.sequential(fromPar(fx)))) def monad: Monad[ExceptT[G, E, _]] = exceptTMonad[G, E](G.monad) @@ -45,8 +45,8 @@ trait ExceptTInstances extends ExceptTInstances1 { } } trait ExceptTInstances1 { - implicit def exceptTMonad[F[+_], E](implicit F: Monad[F]): MonadError[ExceptT[F, E, *], E] = - new MonadError[ExceptT[F, E, *], E] { + implicit def exceptTMonad[F[+_], E](implicit F: Monad[F]): MonadError[ExceptT[F, E, _], E] = + new MonadError[ExceptT[F, E, _], E] { override def map[A, B](fa: ExceptT[F, E, A])(f: A => B): ExceptT[F, E, B] = Embedded(fa.value.map(_.map(f))) @@ -78,8 +78,8 @@ trait ExceptTInstances1 { def raiseError[A](e: E): ExceptT[F, E, A] = Embedded(e.asLeftF[F, A]) } - implicit def exceptTBind[F[+_]](implicit F: Monad[F]): Bind[ExceptT[F, *, *]] = - new Bind[ExceptT[F, *, *]] { + implicit def exceptTBind[F[+_]](implicit F: Monad[F]): Bind[ExceptT[F, _, _]] = + new Bind[ExceptT[F, _, _]] { def pure[E, A](a: A): ExceptT[F, E, A] = Embedded(a.asRightF[F, E]) def raise[E, A](e: E): ExceptT[F, E, A] = Embedded(e.asLeftF[F, A]) @@ -112,12 +112,12 @@ trait ExceptTInstances1 { implicit def exceptTParallel[G[+_], E: Semigroup](implicit G: Monad[G] - ): Parallel.Aux[ExceptT[G, E, *], ExceptTPar[G, E, *]] = - new Parallel[ExceptT[G, E, *]] { + ): Parallel.Aux[ExceptT[G, E, _], ExceptTPar[G, E, _]] = + new Parallel[ExceptT[G, E, _]] { type F[A] = ExceptTPar[G, E, A] - def parallel = funk.funKFrom[ExceptT[G, E, *]](fx => toPar(fx.value)) - def sequential = funk.funK[ExceptTPar[G, E, *], ExceptT[G, E, *]](fx => fromPartoExcept(fx)) + def parallel = funk.funKFrom[ExceptT[G, E, _]](fx => toPar(fx.value)) + def sequential = funk.funK[ExceptTPar[G, E, _], ExceptT[G, E, _]](fx => fromPartoExcept(fx)) def monad: Monad[ExceptT[G, E, _]] = exceptTMonad[G, E] @@ -131,7 +131,7 @@ private[tofu] object ExceptTInstances1 { @inline final def fromPar[F[_], E, A](et: ExceptTPar[F, E, A]) = et.asInstanceOf[F[Either[E, A]]] @inline final def fromPartoExcept[F[+_], E, A](et: ExceptTPar[F, E, A]) = et.asInstanceOf[ExceptT[F, E, A]] - class ParApplicative[F[_]: Applicative, E: Semigroup] extends Applicative[ExceptTPar[F, E, *]] { + class ParApplicative[F[_]: Applicative, E: Semigroup] extends Applicative[ExceptTPar[F, E, _]] { def pure[A](x: A): ExceptTPar[F, E, A] = toPar(x.asRightF[F, E]) def ap[A, B](ff: ExceptTPar[F, E, A => B])(fa: ExceptTPar[F, E, A]): ExceptTPar[F, E, B] = map2(ff, fa)(_(_)) diff --git a/modules/kernel/src/main/scala/tofu/data/Flux.scala b/modules/kernel/src/main/scala/tofu/data/Flux.scala index aaf4e4e76..af7f58aeb 100644 --- a/modules/kernel/src/main/scala/tofu/data/Flux.scala +++ b/modules/kernel/src/main/scala/tofu/data/Flux.scala @@ -25,7 +25,7 @@ object Flux extends FluxInstances { type Infinite[+F[_], A] = Flux[F, Identity, A] type Stream[+F[_], +A] = Flux[F, Option, A] - type Accum[+F[_], +R, +A] = Flux[F, Either[R, +*], A] + type Accum[+F[_], +R, +A] = Flux[F, Either[R, +_], A] final implicit def toFluxOps[F[_], G[_], A](flux: Flux[F, G, A]): FluxOps[F, G, A] = new FluxOps(flux.value) final implicit def toStreamOps[F[_], A](flux: Flux[F, Option, A]): FluxStreamOps[F, A] = @@ -85,8 +85,8 @@ class FluxOps[F[_], G[_], A](private val value: F[G[(A, Flux[F, G, A])]]) extend } trait FluxInstances extends FluxInstances1 { self: Flux.type => - implicit def streamMonad[F[_]: Monad]: Monad[Stream[F, *]] with Alternative[Stream[F, *]] = - new FluxFunctor[F, Option] with StackSafeMonad[Stream[F, *]] with Alternative[Stream[F, *]] { + implicit def streamMonad[F[_]: Monad]: Monad[Stream[F, _]] with Alternative[Stream[F, _]] = + new FluxFunctor[F, Option] with StackSafeMonad[Stream[F, _]] with Alternative[Stream[F, _]] { def pure[A](x: A) = Flux((x, empty[A]).some.pure[F]) def flatMap[A, B](fa: Stream[F, A])(f: A => Stream[F, B]): Stream[F, B] = @@ -104,8 +104,8 @@ trait FluxInstances extends FluxInstances1 { self: Flux.type => }) } - implicit def accumMonad[F[_]: Monad, R: Monoid]: Monad[Accum[F, R, *]] with Alternative[Accum[F, R, *]] = - new FluxFunctor[F, Either[R, +*]] with StackSafeMonad[Accum[F, R, *]] with Alternative[Accum[F, R, *]] { + implicit def accumMonad[F[_]: Monad, R: Monoid]: Monad[Accum[F, R, _]] with Alternative[Accum[F, R, _]] = + new FluxFunctor[F, Either[R, +_]] with StackSafeMonad[Accum[F, R, _]] with Alternative[Accum[F, R, _]] { private def add[A](r: R, f: Accum[F, R, A]): Accum[F, R, A] = Flux(f.value.map { case Left(r1) => Left(r |+| r1) @@ -126,8 +126,8 @@ trait FluxInstances extends FluxInstances1 { self: Flux.type => }) } - implicit def infiniteApplicative[F[_]: Applicative: Defer]: Applicative[Infinite[F, *]] = - new Applicative[Infinite[F, *]] { + implicit def infiniteApplicative[F[_]: Applicative: Defer]: Applicative[Infinite[F, _]] = + new Applicative[Infinite[F, _]] { def pure[A](x: A): Infinite[F, A] = { lazy val result: Infinite[F, A] = Flux[F, Identity, A](Defer[F].defer((x, result).pure[F])) result @@ -140,10 +140,10 @@ trait FluxInstances extends FluxInstances1 { self: Flux.type => } } trait FluxInstances1 { self: Flux.type => - implicit def fluxFunctor[F[_]: Functor, G[_]: Functor]: Functor[Flux[F, G, *]] = new FluxFunctor[F, G] + implicit def fluxFunctor[F[_]: Functor, G[_]: Functor]: Functor[Flux[F, G, _]] = new FluxFunctor[F, G] } -class FluxFunctor[F[_]: Functor, G[_]: Functor] extends Functor[Flux[F, G, *]] { +class FluxFunctor[F[_]: Functor, G[_]: Functor] extends Functor[Flux[F, G, _]] { override def map[A, B](fa: Flux[F, G, A])(f: A => B): Flux[F, G, B] = Flux(fa.value.map(_.map { case (head, tail) => (f(head), map(tail)(f)) })) } diff --git a/modules/kernel/src/main/scala/tofu/data/calc/CalcMInstances.scala b/modules/kernel/src/main/scala/tofu/data/calc/CalcMInstances.scala index e84be64d8..c9cba1f3b 100644 --- a/modules/kernel/src/main/scala/tofu/data/calc/CalcMInstances.scala +++ b/modules/kernel/src/main/scala/tofu/data/calc/CalcMInstances.scala @@ -24,18 +24,18 @@ trait CalcMInstances extends CalcMInstances1 { } trait CalcMInstances1 { - final implicit def calcMBitraverse[F[+_, +_]: Bitraverse, S]: Bitraverse[CalcM[F, Any, Any, S, *, *]] = + final implicit def calcMBitraverse[F[+_, +_]: Bitraverse, S]: Bitraverse[CalcM[F, Any, Any, S, _, _]] = new CalcMBitraverse } trait CalcMInstances2 { - final implicit def calcMBifoldable[F[+_, +_]: Bifoldable, S]: Bifoldable[CalcM[F, Any, Any, S, *, *]] = + final implicit def calcMBifoldable[F[+_, +_]: Bifoldable, S]: Bifoldable[CalcM[F, Any, Any, S, _, _]] = new CalcMBifoldable } class CalcMonadInstance[F[+_, +_], R, S, E] - extends MonadError[CalcM[F, R, S, S, E, *], E] with cats.Defer[CalcM[F, R, S, S, E, *]] - with StackSafeMonad[CalcM[F, R, S, S, E, *]] { + extends MonadError[CalcM[F, R, S, S, E, _], E] with cats.Defer[CalcM[F, R, S, S, E, _]] + with StackSafeMonad[CalcM[F, R, S, S, E, _]] { def defer[A](fa: => CalcM[F, R, S, S, E, A]): CalcM[F, R, S, S, E, A] = CalcM.defer(fa) def raiseError[A](e: E): CalcM[F, R, S, S, E, A] = CalcM.raise(e) def handleErrorWith[A](fa: CalcM[F, R, S, S, E, A])(f: E => CalcM[F, R, S, S, E, A]): CalcM[F, R, S, S, E, A] = @@ -45,7 +45,7 @@ class CalcMonadInstance[F[+_, +_], R, S, E] def pure[A](x: A): CalcM[F, R, S, S, E, A] = CalcM.pure(x) } -class CalcBindInstance[F[+_, +_], R, S] extends StackSafeBind[CalcM[F, R, S, S, *, *]] { +class CalcBindInstance[F[+_, +_], R, S] extends StackSafeBind[CalcM[F, R, S, S, _, _]] { override def pure[E, A](a: A): CalcM[F, R, S, S, E, A] = CalcM.pure(a) override def raise[E, A](e: E): CalcM[F, R, S, S, E, A] = CalcM.raise(e) @@ -56,9 +56,9 @@ class CalcBindInstance[F[+_, +_], R, S] extends StackSafeBind[CalcM[F, R, S, S, ): CalcM[F, R, S, S, X, B] = fa.foldWith(f, h) } -class CalcContextInstance[F[+_, +_], R, S, E] extends WithRun[CalcM[F, R, S, S, E, *], CalcM[F, Any, S, S, E, *], R] { +class CalcContextInstance[F[+_, +_], R, S, E] extends WithRun[CalcM[F, R, S, S, E, _], CalcM[F, Any, S, S, E, _], R] { override val context: CalcM[F, R, S, S, E, R] = CalcM.read - override val functor: Functor[CalcM[F, R, S, S, E, *]] = CalcM.calcFunctorInstance + override val functor: Functor[CalcM[F, R, S, S, E, _]] = CalcM.calcFunctorInstance override def runContext[A](fa: CalcM[F, R, S, S, E, A])(ctx: R): CalcM[F, Any, S, S, E, A] = fa.provide(ctx) override def local[A](fa: CalcM[F, R, S, S, E, A])(project: R => R): CalcM[F, R, S, S, E, A] = @@ -67,8 +67,8 @@ class CalcContextInstance[F[+_, +_], R, S, E] extends WithRun[CalcM[F, R, S, S, } class CalcBiContextInstance[F[+_, +_], R, S] - extends BiRun[CalcM[F, R, S, S, +*, +*], CalcM[F, Any, S, S, +*, +*], Nothing, R] { - override def bifunctor: Bind[CalcM[F, R, S, S, *, *]] = CalcM.calcBindInstance + extends BiRun[CalcM[F, R, S, S, +_, +_], CalcM[F, Any, S, S, +_, +_], Nothing, R] { + override def bifunctor: Bind[CalcM[F, R, S, S, _, _]] = CalcM.calcBindInstance override def lift[E, A](fa: CalcM[F, Any, S, S, E, A]): CalcM[F, R, S, S, E, A] = fa @@ -83,11 +83,11 @@ class CalcBiContextInstance[F[+_, +_], R, S] )(lproj: Nothing => Nothing, rproj: R => R): CalcM[F, R, S, S, E, A] = fea.local(rproj) override def disclose[E, A]( - k: FunBK[CalcM[F, R, S, S, *, *], CalcM[F, Any, S, S, *, *]] => CalcM[F, R, S, S, E, A] - ): CalcM[F, R, S, S, E, A] = CalcM.read[S, R].flatMap(r => k(FunBK.apply[CalcM[F, R, S, S, *, *]](_.provide(r)))) + k: FunBK[CalcM[F, R, S, S, _, _], CalcM[F, Any, S, S, _, _]] => CalcM[F, R, S, S, E, A] + ): CalcM[F, R, S, S, E, A] = CalcM.read[S, R].flatMap(r => k(FunBK.apply[CalcM[F, R, S, S, _, _]](_.provide(r)))) } -class CalcMBifoldable[F[+_, +_], S](implicit F: Bifoldable[F]) extends Bifoldable[CalcM[F, Any, Any, S, *, *]] { +class CalcMBifoldable[F[+_, +_], S](implicit F: Bifoldable[F]) extends Bifoldable[CalcM[F, Any, Any, S, _, _]] { private[this] val MaxDepth = 256 def bifoldLeft1Slow[E, A, B]( @@ -145,7 +145,7 @@ class CalcMBifoldable[F[+_, +_], S](implicit F: Bifoldable[F]) extends Bifoldabl } class CalcMBitraverse[F[+_, +_], S](implicit F: Bitraverse[F]) - extends CalcMBifoldable[F, S] with Bitraverse[CalcM[F, Any, Any, S, *, *]] { + extends CalcMBifoldable[F, S] with Bitraverse[CalcM[F, Any, Any, S, _, _]] { def bitraverse1[G[_]: Applicative, A, B, C, D]( fab: StepResult[F, S, A, B] diff --git a/modules/kernel/src/main/scala/tofu/data/calc/CalcT.scala b/modules/kernel/src/main/scala/tofu/data/calc/CalcT.scala index 6cfe0fbb9..b78213bc9 100644 --- a/modules/kernel/src/main/scala/tofu/data/calc/CalcT.scala +++ b/modules/kernel/src/main/scala/tofu/data/calc/CalcT.scala @@ -2,5 +2,5 @@ package tofu.data package calc object CalcT { - def lift[F[+_], S, A](fa: F[A]): CalcT[F, Any, S, S, Nothing, A] = CalcM.lift[UnaryM[F, +*, +*], S, Nothing, A](fa) + def lift[F[+_], S, A](fa: F[A]): CalcT[F, Any, S, S, Nothing, A] = CalcM.lift[UnaryM[F, +_, +_], S, Nothing, A](fa) } diff --git a/modules/kernel/src/main/scala/tofu/data/calc/Translator.scala b/modules/kernel/src/main/scala/tofu/data/calc/Translator.scala index 3d4fba90a..089ba0ccd 100644 --- a/modules/kernel/src/main/scala/tofu/data/calc/Translator.scala +++ b/modules/kernel/src/main/scala/tofu/data/calc/Translator.scala @@ -24,7 +24,7 @@ object Translator { type Uno[F[_], E, A] = F[A] def apply[F[_, _], R, S]: Applied[F, R, S] = new Applied - def uno[F[_], R, S]: Applied[Uno[F, *, *], R, S] = new Applied[Uno[F, *, *], R, S] + def uno[F[_], R, S]: Applied[Uno[F, _, _], R, S] = new Applied[Uno[F, _, _], R, S] class Applied[F[_, _], R, ST] { type E diff --git a/modules/kernel/src/main/scala/tofu/data/data.scala b/modules/kernel/src/main/scala/tofu/data/data.scala index 01c6b49c8..d57f20710 100644 --- a/modules/kernel/src/main/scala/tofu/data/data.scala +++ b/modules/kernel/src/main/scala/tofu/data/data.scala @@ -8,7 +8,7 @@ package object data { type PArray[+A] = PArray.Type[A] type ICalc[-R, S, +E, +A] = Calc[R, S, S, E, A] type Embedded[+F[+_], +G[+_], +A] = Embedded.T[F, G, A] - type ExceptT[+F[+_], +E, +A] = Embedded[F, Either[E, +*], A] + type ExceptT[+F[+_], +E, +A] = Embedded[F, Either[E, +_], A] type ∘[+F[+_], +G[+_], +A] = Embedded.T[F, G, A] type Flux[+F[_], +G[_], +A] = Flux.FluxRepr[F, G, A] diff --git a/modules/kernel/src/main/scala/tofu/errorInstances/package.scala b/modules/kernel/src/main/scala/tofu/errorInstances/package.scala index 81de953db..7e17932b8 100644 --- a/modules/kernel/src/main/scala/tofu/errorInstances/package.scala +++ b/modules/kernel/src/main/scala/tofu/errorInstances/package.scala @@ -47,7 +47,7 @@ private[tofu] trait HandlePrism[F[_], E, E1] extends Handle[F, E1] { def lift[A](fa: F[A]): F[A] = fa } -private[tofu] class EitherTErrorsTo[F[_]: Monad, E] extends ErrorsTo[EitherT[F, E, *], F, E] { +private[tofu] class EitherTErrorsTo[F[_]: Monad, E] extends ErrorsTo[EitherT[F, E, _], F, E] { def handleWith[A](fa: EitherT[F, E, A])(f: E => F[A]): F[A] = fa.valueOrF(f) // Members declared in tofu.Raise @@ -60,7 +60,7 @@ private[tofu] class EitherTErrorsTo[F[_]: Monad, E] extends ErrorsTo[EitherT[F, def lift[A](fa: F[A]): EitherT[F, E, A] = EitherT.liftF(fa) } -private[tofu] class OptionTErrorsTo[F[_]: Monad] extends ErrorsTo[OptionT[F, *], F, Unit] { +private[tofu] class OptionTErrorsTo[F[_]: Monad] extends ErrorsTo[OptionT[F, _], F, Unit] { def handleWith[A](fa: OptionT[F, A])(f: Unit => F[A]): F[A] = fa.getOrElseF(f(())) // Members declared in tofu.Raise @@ -73,7 +73,7 @@ private[tofu] class OptionTErrorsTo[F[_]: Monad] extends ErrorsTo[OptionT[F, *], def lift[A](fa: F[A]): OptionT[F, A] = OptionT.liftF(fa) } -private[tofu] class EitherErrorsTo[E] extends ErrorsTo[Either[E, *], Id, E] { +private[tofu] class EitherErrorsTo[E] extends ErrorsTo[Either[E, _], Id, E] { def handleWith[A](fa: Either[E, A])(f: E => A): A = fa.fold(f, identity) // Members declared in tofu.Raise diff --git a/modules/kernel/src/main/scala/tofu/internal/instances/perform.scala b/modules/kernel/src/main/scala/tofu/internal/instances/perform.scala index 4ee18fba2..fa1b01e5a 100644 --- a/modules/kernel/src/main/scala/tofu/internal/instances/perform.scala +++ b/modules/kernel/src/main/scala/tofu/internal/instances/perform.scala @@ -37,9 +37,9 @@ class PerformViaMappedPerformer[F[_], C1[_], C2[_], Cancel]( class PerformOfMappedPerformer[F[_], Ex1[_], Ex2[_]]( af: PerformOf[F, Ex1], fk: Ex1 ~> Ex2, -) extends PerformViaMappedPerformer[F, Cont[Ex1, *], Cont[Ex2, *], Unit]( +) extends PerformViaMappedPerformer[F, Cont[Ex1, _], Cont[Ex2, _], Unit]( af, - funK[Cont[Ex2, *], Cont[Ex1, *]](c1 => ex1 => c1(fk(ex1))), + funK[Cont[Ex2, _], Cont[Ex1, _]](c1 => ex1 => c1(fk(ex1))), ) with PerformOf[F, Ex2] final class PerformOfFunctorK[F[_]] extends FunctorK[({ type L[x[_]] = PerformOf[F, x] })#L] { @@ -48,7 +48,7 @@ final class PerformOfFunctorK[F[_]] extends FunctorK[({ type L[x[_]] = PerformOf } final class ReaderTPerformer[F[_], R, C[_], Cancel](p: Performer[F, C, Cancel], r: R) - extends Performer[ReaderT[F, R, *], C, Cancel] { + extends Performer[ReaderT[F, R, _], C, Cancel] { def perform[A](cont: C[A])(f: Kleisli[F, R, A]): Kleisli[F, R, Cancel] = ReaderT.liftF(p.perform(cont)(f.run(r))) } @@ -59,10 +59,10 @@ final class UnliftPerformer[F[_], B[_], C[_], Cancel](p: Performer[B, C, Cancel] } class PerformViaReader[F[_]: Functor, R, C[_], Cancel]( p: PerformVia[F, C, Cancel] -) extends PerformVia[ReaderT[F, R, *], C, Cancel] { - val functor: Functor[ReaderT[F, R, *]] = implicitly +) extends PerformVia[ReaderT[F, R, _], C, Cancel] { + val functor: Functor[ReaderT[F, R, _]] = implicitly - def performer: ReaderT[F, R, Performer[ReaderT[F, R, *], C, Cancel]] = + def performer: ReaderT[F, R, Performer[ReaderT[F, R, _], C, Cancel]] = ReaderT(r => p.performer.map(new ReaderTPerformer(_, r))) } diff --git a/modules/kernel/src/main/scala/tofu/lift/Unlift.scala b/modules/kernel/src/main/scala/tofu/lift/Unlift.scala index 760045eab..373ea8527 100644 --- a/modules/kernel/src/main/scala/tofu/lift/Unlift.scala +++ b/modules/kernel/src/main/scala/tofu/lift/Unlift.scala @@ -32,7 +32,7 @@ object Lift extends LiftInstances1 { } implicit def liftIdentity[F[_]]: Lift[F, F] = liftIdentityAny.asInstanceOf[Lift[F, F]] - private val unliftReaderTAny: Unlift[hktAny.AnyK, ReaderT[hktAny.AnyK, Any, *]] = { + private val unliftReaderTAny: Unlift[hktAny.AnyK, ReaderT[hktAny.AnyK, Any, _]] = { type RT[a] = ReaderT[hktAny.AnyK, Any, a] new Unlift[hktAny.AnyK, RT] { def lift[A](fa: hktAny.AnyK[A]): RT[A] = ReaderT.liftF(fa) @@ -40,8 +40,8 @@ object Lift extends LiftInstances1 { val unlift: RT[RT ~> AnyK] = ReaderT[AnyK, Any, RT ~> AnyK](r => funK[RT, AnyK](f => f.run(r))) } } - implicit def liftReaderT[F[_], R]: Lift[F, ReaderT[F, R, *]] = - unliftReaderTAny.asInstanceOf[Unlift[F, ReaderT[F, R, *]]] + implicit def liftReaderT[F[_], R]: Lift[F, ReaderT[F, R, _]] = + unliftReaderTAny.asInstanceOf[Unlift[F, ReaderT[F, R, _]]] } private[lift] trait LiftInstances1 extends LiftInstances2 { diff --git a/modules/kernel/src/test/scala/tofu/ContextSummonSuite.scala b/modules/kernel/src/test/scala/tofu/ContextSummonSuite.scala index db3ba8a86..61abea07e 100644 --- a/modules/kernel/src/test/scala/tofu/ContextSummonSuite.scala +++ b/modules/kernel/src/test/scala/tofu/ContextSummonSuite.scala @@ -10,27 +10,27 @@ object ContextSummonSuite { type R[F[_], x] = ReaderT[F, Ctx, x] def summonReaderTComposeInstances[F[_], G[_]: Monad](implicit U: Unlift[F, G]): Any = { - implicitly[Unlift[F, R[G, *]]] + implicitly[Unlift[F, R[G, _]]] } def summonReaderTWrappedInstances1[F[_], G[_], C](implicit WR: WithRun[G, F, C]): Any = { - implicitly[WithContext[R[G, *], C]] - implicitly[WithLocal[R[G, *], C]] - implicitly[WithRun[R[G, *], R[F, *], C]] - implicitly[Unlift[R[F, *], R[G, *]]] + implicitly[WithContext[R[G, _], C]] + implicitly[WithLocal[R[G, _], C]] + implicitly[WithRun[R[G, _], R[F, _], C]] + implicitly[Unlift[R[F, _], R[G, _]]] } def summonReaderTWrappedInstances2[F[_], G[_], C](implicit WP: WithProvide[G, F, C]): Any = { - implicitly[WithProvide[R[G, *], R[F, *], C]] + implicitly[WithProvide[R[G, _], R[F, _], C]] } def summonReaderTWrappedInstances3[F[_], C](implicit WL: WithLocal[F, C]): Any = { - implicitly[WithContext[R[F, *], C]] - implicitly[WithLocal[R[F, *], C]] + implicitly[WithContext[R[F, _], C]] + implicitly[WithLocal[R[F, _], C]] } def summonReaderTWrappedInstances4[F[_], C](implicit WC: WithContext[F, C]): Any = { - implicitly[WithContext[R[F, *], C]] + implicitly[WithContext[R[F, _], C]] } } diff --git a/modules/logging/structured/src/main/scala/tofu/logging/LoggingMid.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggingMid.scala index 07effbb37..c0e2318eb 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/LoggingMid.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LoggingMid.scala @@ -20,7 +20,7 @@ object LoggingMid extends builder.LoggingMidBuilder.DefaultImpl with LoggingMidM type Of[U[_[_]]] = U[LoggingMid] } -/** Logging middleware supporting error reporting Alg[LoggingErrMid[E, *]] is a special form of implicit evidence of +/** Logging middleware supporting error reporting Alg[LoggingErrMid[E, _]] is a special form of implicit evidence of * injectable logging support generally you don't need `Logging` instance to derive this so choice of logging postponed * until this middleware is attached to the core instance */ diff --git a/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInvariantSyntax.scala b/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInvariantSyntax.scala index d36cb1221..ca3b9b719 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInvariantSyntax.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/internal/LogsInvariantSyntax.scala @@ -34,13 +34,13 @@ object LogsInvariantSyntax { ): I[Logs.Universal[F]] = cached.map(_.universal) /** Collection of useful methods for creating middleware - * {{{logs.logged[Service].mid(implicit l => new Service[Mid[F, *]]{... })}}} + * {{{logs.logged[Service].mid(implicit l => new Service[Mid[F, _]]{... })}}} */ final def logged[U[_[_]]](implicit c: ClassTag[U[HKAny]]): LogWares[U, I, F] = new LogWares(logs.forService[U[HKAny]]) /** Collection of useful methods for creating middleware - * {{{logs.nameLogged[Service]("service").mid(implicit l => new Service[Mid[F, *]]{... })}}} + * {{{logs.nameLogged[Service]("service").mid(implicit l => new Service[Mid[F, _]]{... })}}} */ final def nameLogged[U[_[_]]](name: String): LogWares[U, I, F] = new LogWares(logs.byName(name)) From ad807ebf2c72b870ad08fa462356546d15deffba Mon Sep 17 00:00:00 2001 From: Vladislav Ugryumov Date: Wed, 3 Apr 2024 02:36:20 +0300 Subject: [PATCH 4/9] Revert renaming non migrated module. --- .../main/{scala => scala-2}/tofu/common/derived/display.scala | 0 .../{scala => scala-2}/tofu/data/derived/InitDerivation.scala | 0 .../src/main/{scala => scala-2}/tofu/data/derived/Merge.scala | 0 .../{scala => scala-2}/tofu/data/derived/MerkatorFromCats.scala | 0 .../src/main/{scala => scala-2}/tofu/data/derived/package.scala | 0 .../tofu/higherKind/derived/ContextEmbed.scala | 0 .../{scala => scala-2}/tofu/higherKind/derived/derived.scala | 0 .../src/main/{scala => scala-2}/tofu/syntax/merge.scala | 0 .../{scala => scala-2}/tofu/common/derived/DisplaySpec.scala | 0 .../test/{scala => scala-2}/tofu/data/derived/MergeSuite.scala | 0 .../{scala => scala-2}/tofu/higherKind/derived/EmbedSuite.scala | 0 .../tofu/higherKind/derived/RepresentableKSuite.scala | 0 .../tofu/higherKind/derived/RepresentableKVarArgSuite.scala | 0 .../src/main/scala/tofu/logging/LoggableInstances.scala | 2 +- 14 files changed, 1 insertion(+), 1 deletion(-) rename modules/derivation/src/main/{scala => scala-2}/tofu/common/derived/display.scala (100%) rename modules/derivation/src/main/{scala => scala-2}/tofu/data/derived/InitDerivation.scala (100%) rename modules/derivation/src/main/{scala => scala-2}/tofu/data/derived/Merge.scala (100%) rename modules/derivation/src/main/{scala => scala-2}/tofu/data/derived/MerkatorFromCats.scala (100%) rename modules/derivation/src/main/{scala => scala-2}/tofu/data/derived/package.scala (100%) rename modules/derivation/src/main/{scala => scala-2}/tofu/higherKind/derived/ContextEmbed.scala (100%) rename modules/derivation/src/main/{scala => scala-2}/tofu/higherKind/derived/derived.scala (100%) rename modules/derivation/src/main/{scala => scala-2}/tofu/syntax/merge.scala (100%) rename modules/derivation/src/test/{scala => scala-2}/tofu/common/derived/DisplaySpec.scala (100%) rename modules/derivation/src/test/{scala => scala-2}/tofu/data/derived/MergeSuite.scala (100%) rename modules/derivation/src/test/{scala => scala-2}/tofu/higherKind/derived/EmbedSuite.scala (100%) rename modules/derivation/src/test/{scala => scala-2}/tofu/higherKind/derived/RepresentableKSuite.scala (100%) rename modules/derivation/src/test/{scala => scala-2}/tofu/higherKind/derived/RepresentableKVarArgSuite.scala (100%) diff --git a/modules/derivation/src/main/scala/tofu/common/derived/display.scala b/modules/derivation/src/main/scala-2/tofu/common/derived/display.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/common/derived/display.scala rename to modules/derivation/src/main/scala-2/tofu/common/derived/display.scala diff --git a/modules/derivation/src/main/scala/tofu/data/derived/InitDerivation.scala b/modules/derivation/src/main/scala-2/tofu/data/derived/InitDerivation.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/data/derived/InitDerivation.scala rename to modules/derivation/src/main/scala-2/tofu/data/derived/InitDerivation.scala diff --git a/modules/derivation/src/main/scala/tofu/data/derived/Merge.scala b/modules/derivation/src/main/scala-2/tofu/data/derived/Merge.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/data/derived/Merge.scala rename to modules/derivation/src/main/scala-2/tofu/data/derived/Merge.scala diff --git a/modules/derivation/src/main/scala/tofu/data/derived/MerkatorFromCats.scala b/modules/derivation/src/main/scala-2/tofu/data/derived/MerkatorFromCats.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/data/derived/MerkatorFromCats.scala rename to modules/derivation/src/main/scala-2/tofu/data/derived/MerkatorFromCats.scala diff --git a/modules/derivation/src/main/scala/tofu/data/derived/package.scala b/modules/derivation/src/main/scala-2/tofu/data/derived/package.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/data/derived/package.scala rename to modules/derivation/src/main/scala-2/tofu/data/derived/package.scala diff --git a/modules/derivation/src/main/scala/tofu/higherKind/derived/ContextEmbed.scala b/modules/derivation/src/main/scala-2/tofu/higherKind/derived/ContextEmbed.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/higherKind/derived/ContextEmbed.scala rename to modules/derivation/src/main/scala-2/tofu/higherKind/derived/ContextEmbed.scala diff --git a/modules/derivation/src/main/scala/tofu/higherKind/derived/derived.scala b/modules/derivation/src/main/scala-2/tofu/higherKind/derived/derived.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/higherKind/derived/derived.scala rename to modules/derivation/src/main/scala-2/tofu/higherKind/derived/derived.scala diff --git a/modules/derivation/src/main/scala/tofu/syntax/merge.scala b/modules/derivation/src/main/scala-2/tofu/syntax/merge.scala similarity index 100% rename from modules/derivation/src/main/scala/tofu/syntax/merge.scala rename to modules/derivation/src/main/scala-2/tofu/syntax/merge.scala diff --git a/modules/derivation/src/test/scala/tofu/common/derived/DisplaySpec.scala b/modules/derivation/src/test/scala-2/tofu/common/derived/DisplaySpec.scala similarity index 100% rename from modules/derivation/src/test/scala/tofu/common/derived/DisplaySpec.scala rename to modules/derivation/src/test/scala-2/tofu/common/derived/DisplaySpec.scala diff --git a/modules/derivation/src/test/scala/tofu/data/derived/MergeSuite.scala b/modules/derivation/src/test/scala-2/tofu/data/derived/MergeSuite.scala similarity index 100% rename from modules/derivation/src/test/scala/tofu/data/derived/MergeSuite.scala rename to modules/derivation/src/test/scala-2/tofu/data/derived/MergeSuite.scala diff --git a/modules/derivation/src/test/scala/tofu/higherKind/derived/EmbedSuite.scala b/modules/derivation/src/test/scala-2/tofu/higherKind/derived/EmbedSuite.scala similarity index 100% rename from modules/derivation/src/test/scala/tofu/higherKind/derived/EmbedSuite.scala rename to modules/derivation/src/test/scala-2/tofu/higherKind/derived/EmbedSuite.scala diff --git a/modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKSuite.scala b/modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKSuite.scala similarity index 100% rename from modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKSuite.scala rename to modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKSuite.scala diff --git a/modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKVarArgSuite.scala b/modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKVarArgSuite.scala similarity index 100% rename from modules/derivation/src/test/scala/tofu/higherKind/derived/RepresentableKVarArgSuite.scala rename to modules/derivation/src/test/scala-2/tofu/higherKind/derived/RepresentableKVarArgSuite.scala diff --git a/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala b/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala index 96c15b5f8..f9f376140 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/LoggableInstances.scala @@ -139,7 +139,7 @@ class LoggableInstances { } final implicit def seqLoggable[A: Loggable]: Loggable[collection.Seq[A]] = fldLoggable[Iterable, A].narrow - final implicit def immutableSeqLoggable[A: Loggable]: Loggable[Seq[A]] = + final implicit def immutableSeqLoggable[A: Loggable]: Loggable[Seq[A]] = fldLoggable[Iterable, A].narrow final implicit def listLoggable[A: Loggable]: Loggable[List[A]] = fldLoggable[List, A] From cd383fe946ec53f58405e8410961eb0862918eba Mon Sep 17 00:00:00 2001 From: Vladislav Ugryumov Date: Thu, 4 Apr 2024 15:46:51 +0300 Subject: [PATCH 5/9] Move masking to common code, add "def instance" to scala 3 implementation, add show derivation with masking feature. --- ...Impl.scala => LoggingDerivationImpl.scala} | 2 +- .../{show.scala => ShowDerivationImpl.scala} | 2 +- .../main/scala-2/tofu/magnolia/compat.scala | 9 ++ ...Impl.scala => LoggingDerivationImpl.scala} | 4 +- .../derivation/ShowDerivationImpl.scala | 18 ++++ .../tofu/logging/derivation/masking.scala | 94 ------------------- .../main/scala-3/tofu/magnolia/compat.scala | 9 ++ .../tofu/logging/derivation/loggable.scala | 2 +- .../tofu/logging/derivation/masking.scala | 5 +- .../scala/tofu/logging/derivation/show.scala | 3 + .../tofu/logging/derivation/Disc.scala | 1 + 11 files changed, 49 insertions(+), 100 deletions(-) rename modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/{DerivationImpl.scala => LoggingDerivationImpl.scala} (96%) rename modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/{show.scala => ShowDerivationImpl.scala} (93%) create mode 100644 modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala rename modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/{DerivationImpl.scala => LoggingDerivationImpl.scala} (93%) create mode 100644 modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/ShowDerivationImpl.scala delete mode 100644 modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala create mode 100644 modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala rename modules/logging/derivation/src/main/{scala-2 => scala}/tofu/logging/derivation/masking.scala (95%) create mode 100644 modules/logging/derivation/src/main/scala/tofu/logging/derivation/show.scala rename modules/logging/derivation/src/test/{scala-2 => scala}/tofu/logging/derivation/Disc.scala (99%) diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/DerivationImpl.scala b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/LoggingDerivationImpl.scala similarity index 96% rename from modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/DerivationImpl.scala rename to modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/LoggingDerivationImpl.scala index 315d2dbd1..25fa627b8 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/DerivationImpl.scala +++ b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/LoggingDerivationImpl.scala @@ -6,7 +6,7 @@ import magnolia1.{CaseClass, Magnolia, SealedTrait} import derevo.Derivation import derevo.NewTypeDerivation -trait DerivationImpl extends Derivation[Loggable] with NewTypeDerivation[Loggable] { +trait LoggingDerivationImpl extends Derivation[Loggable] with NewTypeDerivation[Loggable] { type Typeclass[A] = Loggable[A] def byShow[T: Show](name: String): Loggable[T] = diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/show.scala b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/ShowDerivationImpl.scala similarity index 93% rename from modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/show.scala rename to modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/ShowDerivationImpl.scala index e5b3ad97d..0bf34e182 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/show.scala +++ b/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/ShowDerivationImpl.scala @@ -6,7 +6,7 @@ import magnolia1.{CaseClass, Magnolia, SealedTrait} import derevo.Derivation import derevo.NewTypeDerivation -object show extends Derivation[Show] with NewTypeDerivation[Show] { +trait ShowDerivationImpl extends Derivation[Show] with NewTypeDerivation[Show] { /** the type constructor for new [[Show]] instances * diff --git a/modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala b/modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala new file mode 100644 index 000000000..f6f994608 --- /dev/null +++ b/modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala @@ -0,0 +1,9 @@ +package tofu.magnolia + +object compat { + type Param[Typeclass[_], Type] = magnolia1.Param[Typeclass, Type] + + def deref[Typeclass[_], Type](p: Param[Typeclass, Type]): Type => p.PType = tpe => + p.dereference(tpe) + +} diff --git a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/DerivationImpl.scala b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/LoggingDerivationImpl.scala similarity index 93% rename from modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/DerivationImpl.scala rename to modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/LoggingDerivationImpl.scala index cea547011..8f2a26559 100644 --- a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/DerivationImpl.scala +++ b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/LoggingDerivationImpl.scala @@ -3,8 +3,9 @@ package derivation import cats.Show import magnolia1.* +import scala.deriving.Mirror -trait DerivationImpl extends AutoDerivation[Loggable] { +trait LoggingDerivationImpl extends AutoDerivation[Loggable] { def byShow[T: Show](name: String): Loggable[T] = Loggable.stringValue.contramap(Show[T].show).named(name) @@ -54,4 +55,5 @@ trait DerivationImpl extends AutoDerivation[Loggable] { ctx.choose(a)(sub => sub.typeclass.putField(sub.cast(a), name, input)) } + inline def instance[A](using Mirror.Of[A]): Loggable[A] = autoDerived[A] } diff --git a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/ShowDerivationImpl.scala b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/ShowDerivationImpl.scala new file mode 100644 index 000000000..8cf064096 --- /dev/null +++ b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/ShowDerivationImpl.scala @@ -0,0 +1,18 @@ +package tofu.logging +package derivation + +import cats.Show +import magnolia1.* + +trait ShowDerivationImpl extends AutoDerivation[Show] { + + def join[T](ctx: CaseClass[Typeclass, T]): Show[T] = value => + if (ctx.isValueClass) { + val param = ctx.parameters.head + param.typeclass.show(param.deref(value)) + } else strJoin(ctx.typeInfo.short, masking.params[Typeclass, T](value, ctx.parameters)(_.show)) + + def split[T](ctx: SealedTrait[Typeclass, T]): Show[T] = value => + ctx.choose(value)(sub => sub.typeclass.show(sub.cast(value))) + +} diff --git a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala b/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala deleted file mode 100644 index 2215e490f..000000000 --- a/modules/logging/derivation/src/main/scala-3/tofu/logging/derivation/masking.scala +++ /dev/null @@ -1,94 +0,0 @@ -package tofu.logging.derivation - -import scala.annotation.tailrec -import scala.util.matching.Regex - -import magnolia1.CaseClass.Param - -sealed trait MaskMode -object MaskMode { - - /** Replaces each digit with "#" and each letter with "*". Other symbols are not changed */ - case object Full extends MaskMode - - /** Replaces value with "..." */ - case object Erase extends MaskMode - - /** Same as [[Full]] but for some part of value */ - case class ForLength(offset: Int, maxLength: Int = -1) extends MaskMode { - def this(length: Int) = this(0, length) - } - case class Regexp(pattern: Regex) extends MaskMode -} - -object masking { - private val SomeRe = "(?<=^Some(\\{value=|\\())(.+)(?=(\\}|\\))$)".r - - private[derivation] def string(shown: String, mode: MaskMode) = { - @tailrec - def loop(arr: Array[Char], cur: Int, left: Int): String = { - if (left == 0 || cur == arr.length) new String(arr) - else { - val char = arr(cur) - if (char.isDigit) arr(cur) = '#' - else if (char.isLetter) arr(cur) = '*' - - loop(arr, cur + 1, left - 1) - } - } - - mode match { - case MaskMode.Erase => - "..." - case MaskMode.Full => - loop(shown.toCharArray, 0, shown.length) - case MaskMode.Regexp(pattern) => - pattern - .findFirstMatchIn(shown) - .collect { - case m if m.groupCount == 1 => - val start = m.start(1) - val end = m.end(1) - - loop(shown.toCharArray, start, end - start) - } - .getOrElse(shown) - case MaskMode.ForLength(offset, maxLength) => - loop(shown.toCharArray, shown.length min (offset max 0), if (maxLength == -1) shown.length else maxLength) - } - } - - private[derivation] def field[T](field: T, shown: String, mode: MaskMode) = field match { - case None => shown - case Some(_) => SomeRe.replaceSomeIn(shown, m => Some(string(m.toString, mode))) - case _ => string(shown, mode) - } - - private[derivation] def params[TypeClass[_], Type]( - tpe: Type, - params: Seq[Param[TypeClass, Type]] - )(fn: TypeClass[Any] => Any => String) = - params.iterator - .filterNot(_.annotations.contains(hidden())) - .flatMap { param => - import param._ - - val value: PType = deref(tpe) - if (value == None && param.annotations.contains(ignoreOpt())) - None - else { - val shown = fn(typeclass.asInstanceOf[TypeClass[Any]])(value) - - val repr = annotations.collectFirst { case masked(mode) => field(value, shown, mode) } - .getOrElse(shown) - - Some(s"$label=$repr") - } - } - - implicit final class Ops(private val value: String) extends AnyVal { - def mask: String = mask(MaskMode.Full) - - def mask(mode: MaskMode): String = string(value, mode) - } -} diff --git a/modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala b/modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala new file mode 100644 index 000000000..19edaa0aa --- /dev/null +++ b/modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala @@ -0,0 +1,9 @@ +package tofu.magnolia + +object compat { + type Param[Typeclass[_], Type] = magnolia1.CaseClass.Param[Typeclass, Type] + + def deref[Typeclass[_], Type](p: Param[Typeclass, Type]): Type => p.PType = tpe => + p.deref(tpe) + +} diff --git a/modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala index af709f974..7c982a55d 100644 --- a/modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala +++ b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/loggable.scala @@ -1,3 +1,3 @@ package tofu.logging.derivation -object loggable extends DerivationImpl +object loggable extends LoggingDerivationImpl diff --git a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/masking.scala b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/masking.scala similarity index 95% rename from modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/masking.scala rename to modules/logging/derivation/src/main/scala/tofu/logging/derivation/masking.scala index 70cae2e00..f96607682 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/logging/derivation/masking.scala +++ b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/masking.scala @@ -3,7 +3,8 @@ package tofu.logging.derivation import scala.annotation.tailrec import scala.util.matching.Regex -import magnolia1.Param +import tofu.magnolia.compat +import tofu.magnolia.compat.Param sealed trait MaskMode object MaskMode { @@ -71,7 +72,7 @@ object masking { .flatMap { param => import param._ - val value: PType = dereference(tpe) + val value: PType = compat.deref[TypeClass, Type](param)(tpe) if (value == None && param.annotations.contains(ignoreOpt())) None else { diff --git a/modules/logging/derivation/src/main/scala/tofu/logging/derivation/show.scala b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/show.scala new file mode 100644 index 000000000..45104ccaf --- /dev/null +++ b/modules/logging/derivation/src/main/scala/tofu/logging/derivation/show.scala @@ -0,0 +1,3 @@ +package tofu.logging.derivation + +object show extends ShowDerivationImpl diff --git a/modules/logging/derivation/src/test/scala-2/tofu/logging/derivation/Disc.scala b/modules/logging/derivation/src/test/scala/tofu/logging/derivation/Disc.scala similarity index 99% rename from modules/logging/derivation/src/test/scala-2/tofu/logging/derivation/Disc.scala rename to modules/logging/derivation/src/test/scala/tofu/logging/derivation/Disc.scala index 5a4fa22d6..43d5fe7d8 100644 --- a/modules/logging/derivation/src/test/scala-2/tofu/logging/derivation/Disc.scala +++ b/modules/logging/derivation/src/test/scala/tofu/logging/derivation/Disc.scala @@ -1,4 +1,5 @@ package tofu.logging.derivation + import tofu.compat.unused import tofu.logging.{LogTree, Loggable} import tofu.syntax.loggable._ From 58dfaa3e3516c79de0c9bb9f6efa329cf6fad865 Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Mon, 8 Apr 2024 18:26:15 +0300 Subject: [PATCH 6/9] upgrade tethys to 0.28.3 --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index cb61e62d7..9ba3b61a2 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -14,7 +14,7 @@ object Dependencies { val circe = "0.14.5" - val tethys = "0.28.0" + val tethys = "0.28.3" val cats = "2.9.0" From ea518dc8f8d49e43fa61e8ab62d1071270e4fc4b Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Mon, 8 Apr 2024 20:28:05 +0300 Subject: [PATCH 7/9] fmt --- .../derivation/src/main/scala-2/tofu/magnolia/compat.scala | 3 +-- .../derivation/src/main/scala-3/tofu/magnolia/compat.scala | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala b/modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala index f6f994608..bf15cf9e4 100644 --- a/modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala +++ b/modules/logging/derivation/src/main/scala-2/tofu/magnolia/compat.scala @@ -3,7 +3,6 @@ package tofu.magnolia object compat { type Param[Typeclass[_], Type] = magnolia1.Param[Typeclass, Type] - def deref[Typeclass[_], Type](p: Param[Typeclass, Type]): Type => p.PType = tpe => - p.dereference(tpe) + def deref[Typeclass[_], Type](p: Param[Typeclass, Type]): Type => p.PType = tpe => p.dereference(tpe) } diff --git a/modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala b/modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala index 19edaa0aa..a31e41a7f 100644 --- a/modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala +++ b/modules/logging/derivation/src/main/scala-3/tofu/magnolia/compat.scala @@ -3,7 +3,6 @@ package tofu.magnolia object compat { type Param[Typeclass[_], Type] = magnolia1.CaseClass.Param[Typeclass, Type] - def deref[Typeclass[_], Type](p: Param[Typeclass, Type]): Type => p.PType = tpe => - p.deref(tpe) + def deref[Typeclass[_], Type](p: Param[Typeclass, Type]): Type => p.PType = tpe => p.deref(tpe) } From c6eb3140ee8a70754201fb632bd7a9f6749419a3 Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Mon, 8 Apr 2024 21:03:15 +0300 Subject: [PATCH 8/9] logging - 2.12 compilation fixes --- modules/kernel/src/main/scala/tofu/common/Display.scala | 2 +- .../src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala | 2 +- .../main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala | 4 ++-- .../main/scala/tofu/logging/builder/LoggingMidBuilder.scala | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/kernel/src/main/scala/tofu/common/Display.scala b/modules/kernel/src/main/scala/tofu/common/Display.scala index d8afdcc77..ef2fcfe25 100644 --- a/modules/kernel/src/main/scala/tofu/common/Display.scala +++ b/modules/kernel/src/main/scala/tofu/common/Display.scala @@ -1,7 +1,7 @@ package tofu.common import cats.{Eval, Show} import java.util.UUID -import scala.collection.immutable.{BitSet, Queue, SortedMap, SortedSet} +import scala.collection.immutable.{BitSet, Queue, Seq, SortedMap, SortedSet} import scala.concurrent.duration.Duration import scala.util.Try diff --git a/modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala b/modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala index 53b8ae2b7..18eab6b2c 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/bi/LoggingBiCompanion.scala @@ -10,7 +10,7 @@ import tofu.syntax.functorbk._ import tofu.syntax.monadic._ trait LoggingBiCompanion[U[_[_, _]]] { - type Log[F[_, _]] = ServiceLogging[F[Nothing, _], U[({ type L[_, _] = Any })#L]] + type Log[F[_, _]] = ServiceLogging[F[Nothing, _], U[({ type L[a, b] = Any })#L]] implicit def toBiLogBiMidOps[F[+_, +_]](uf: U[F]): LogBiMidOps[U, F] = new LogBiMidOps(uf) diff --git a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala index b6591c4b8..41338fed0 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingBiMidBuilder.scala @@ -11,7 +11,7 @@ import scala.collection.mutable.Buffer import scala.reflect.ClassTag trait BiBuilder[+T[_, _]] { - def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[({ type L[_, _] = Any })#L]]): BiPrepared[Alg, T] + def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[({ type L[a, b] = Any })#L]]): BiPrepared[Alg, T] } trait BiMethod[U[f[_, _]], Err, Res, +T[_, _]] { @@ -42,7 +42,7 @@ abstract class LoggingBiMidBuilder extends BiBuilder[LoggingBiMid] { ok: Boolean ): F[Nothing, Unit] - def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[({ type L[_, _] = Any })#L]]) = + def prepare[Alg[_[_, _]]](implicit Alg: ClassTag[Alg[({ type L[a, b] = Any })#L]]) = new PreparedImpl[Alg](Alg.runtimeClass) protected class MethodImpl[U[f[_, _]], Err: Loggable, Res: Loggable]( diff --git a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala index 174fa4cb8..1e8547c86 100644 --- a/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala +++ b/modules/logging/structured/src/main/scala/tofu/logging/builder/LoggingMidBuilder.scala @@ -92,7 +92,7 @@ object LoggingMidBuilder { class CustomLevelImpl(logLevel: Level) extends CustomLevel { override def onLog[F[_]](message: String, values: LoggedValue*)(implicit F: LoggingBase[F]): F[Unit] = - F.write(logLevel, message, values) + F.write(logLevel, message, values: _*) } } @@ -162,6 +162,6 @@ object LoggingErrMidBuilder { class CustomLevelImpl[E](logLevel: Level, errorLogLevel: Level)(implicit val errLoggable: Loggable[E]) extends LoggingMidBuilder.CustomLevelImpl(logLevel) with CustomLevel[E] { override def onFaultLog[F[_]](message: String, values: LoggedValue*)(implicit F: LoggingBase[F]): F[Unit] = - F.write(errorLogLevel, message, values) + F.write(errorLogLevel, message, values: _*) } } From b1b0b2dec54d65b942f20ccb812e52c3e535829e Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Mon, 8 Apr 2024 21:33:49 +0300 Subject: [PATCH 9/9] tethys: use scala3 artifact --- build.sbt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index ea7ad1a4b..3c9cadbf2 100644 --- a/build.sbt +++ b/build.sbt @@ -133,9 +133,8 @@ lazy val loggingStr = projectMatrix libraryDependencies ++= Seq( catsCore, circeCore, - // it is impossible to use tethys compiled for scala 3 until https://github.com/tethys-json/tethys/issues/266 is resolved - tethys cross CrossVersion.for3Use2_13, - tethysJackson cross CrossVersion.for3Use2_13, + tethys, + tethysJackson, slf4j, alleycats, catsTaglessCore,