diff --git a/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SealedPrograms.scala b/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SealedPrograms.scala index 49fccb8..12bb34a 100644 --- a/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SealedPrograms.scala +++ b/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SealedPrograms.scala @@ -4,13 +4,13 @@ import java.util.concurrent.TimeUnit import cats.Monad import cats.data.{EitherT, OptionT} -import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole import scala.util.{Random, Try} object SealedPrograms { - import cats.instances.try_._ + import cats.instances.try_.* type M[A] = Try[A] implicit val M: Monad[Try] = Monad[Try] @@ -30,8 +30,8 @@ object SealedPrograms { @Fork(1) class SealedPrograms { - import SealedPrograms._ - import pl.iterators.sealedmonad.syntax._ + import SealedPrograms.* + import pl.iterators.sealedmonad.syntax.* private val tokens = 1024 diff --git a/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SingleSealedOps.scala b/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SingleSealedOps.scala index 542cda5..262e787 100644 --- a/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SingleSealedOps.scala +++ b/benchmarks/src/main/scala/pl/iterators/sealedmonad/benchmarks/SingleSealedOps.scala @@ -5,11 +5,11 @@ import java.util.concurrent.TimeUnit import cats.Monad import cats.data.EitherT import cats.instances.TryInstances -import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole import pl.iterators.sealedmonad.Sealed -import scala.util._ +import scala.util.* object SingleSealedOps extends TryInstances { sealed trait ADT @@ -28,7 +28,7 @@ object SingleSealedOps extends TryInstances { @Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(1) class SingleSealedOps { - import SingleSealedOps._ + import SingleSealedOps.* @Param(Array("0", "2", "4", "8", "16", "32", "64", "128")) var tokens: Int = _ diff --git a/build.sbt b/build.sbt index ec494ae..af71db2 100644 --- a/build.sbt +++ b/build.sbt @@ -94,8 +94,8 @@ lazy val noPublishSettings = lazy val examples = project .in(file("examples")) .dependsOn(sealedMonad.jvm % "test->test;compile->compile") - .settings(baseSettings: _*) - .settings(noPublishSettings: _*) + .settings(baseSettings *) + .settings(noPublishSettings *) .settings( name := "examples", description := "Sealed monad - snippets of example code", @@ -106,8 +106,8 @@ lazy val docs = project .in(file("sealed-docs")) .dependsOn(sealedMonad.jvm % "test->test;compile->compile") .enablePlugins(MdocPlugin, DocusaurusPlugin) - .settings(baseSettings: _*) - .settings(noPublishSettings: _*) + .settings(baseSettings *) + .settings(noPublishSettings *) .settings( name := "docs", description := "Sealed monad documentation", @@ -123,8 +123,8 @@ lazy val benchmarks = project .in(file("benchmarks")) .dependsOn(sealedMonad.jvm % "test->test;compile->compile") .enablePlugins(JmhPlugin) - .settings(baseSettings: _*) - .settings(noPublishSettings: _*) + .settings(baseSettings *) + .settings(noPublishSettings *) .settings( name := "benchmarks", description := "Sealed monad benchmarks", @@ -138,7 +138,7 @@ lazy val sealedMonad = crossProject(JSPlatform, JVMPlatform, NativePlatform) .crossType(CrossType.Pure) .in(file("sealedmonad")) .jsConfigure(_.disablePlugins(DoctestPlugin)) - .settings(baseSettings: _*) + .settings(baseSettings *) .settings( name := "sealed-monad", description := "Scala library for nice for-comprehension-style error handling" diff --git a/examples/src/main/scala/pl/iterators/sealedmonad/examples/Options.scala b/examples/src/main/scala/pl/iterators/sealedmonad/examples/Options.scala index ad80ce9..a617e9e 100644 --- a/examples/src/main/scala/pl/iterators/sealedmonad/examples/Options.scala +++ b/examples/src/main/scala/pl/iterators/sealedmonad/examples/Options.scala @@ -2,8 +2,8 @@ package pl.iterators.sealedmonad.examples import cats.Monad import cats.data.{EitherT, OptionT} -import cats.syntax.flatMap._ -import cats.syntax.functor._ +import cats.syntax.flatMap.* +import cats.syntax.functor.* import pl.iterators.sealedmonad.Sealed import scala.language.higherKinds @@ -11,7 +11,7 @@ import scala.language.higherKinds object Options { object Example1 { - import pl.iterators.sealedmonad.syntax._ + import pl.iterators.sealedmonad.syntax.* def login[M[_]]( email: String, @@ -63,7 +63,7 @@ object Options { } object Example2 { - import pl.iterators.sealedmonad.syntax._ + import pl.iterators.sealedmonad.syntax.* def confirmEmail[M[_]: Monad]( token: String, @@ -100,7 +100,7 @@ object Options { } class Example3[M[_]: Monad] { - import pl.iterators.sealedmonad.syntax._ + import pl.iterators.sealedmonad.syntax.* def sealedLogin(email: String): M[LoginResponse] = (for { diff --git a/examples/src/test/scala/pl/iterators/sealedmonad/examples/AllTests.scala b/examples/src/test/scala/pl/iterators/sealedmonad/examples/AllTests.scala index 039af43..961558b 100644 --- a/examples/src/test/scala/pl/iterators/sealedmonad/examples/AllTests.scala +++ b/examples/src/test/scala/pl/iterators/sealedmonad/examples/AllTests.scala @@ -2,7 +2,7 @@ package pl.iterators.sealedmonad.examples import cats.{Eq, Monad} import org.scalacheck.{Arbitrary, Cogen} -import Options._ +import Options.* import org.typelevel.discipline.Laws import org.scalacheck.Prop diff --git a/examples/src/test/scala/pl/iterators/sealedmonad/examples/OptionsTests.scala b/examples/src/test/scala/pl/iterators/sealedmonad/examples/OptionsTests.scala index 4f88742..7f4fac4 100644 --- a/examples/src/test/scala/pl/iterators/sealedmonad/examples/OptionsTests.scala +++ b/examples/src/test/scala/pl/iterators/sealedmonad/examples/OptionsTests.scala @@ -1,19 +1,19 @@ package pl.iterators.sealedmonad.examples import cats.{Eq, Monad} -import org.scalacheck.Prop._ -import org.scalacheck._ +import org.scalacheck.Prop.* +import org.scalacheck.* import org.typelevel.discipline.Laws -import pl.iterators.sealedmonad.examples.Options._ -import pl.iterators.sealedmonad.examples.Options._ +import pl.iterators.sealedmonad.examples.Options.* +import pl.iterators.sealedmonad.examples.Options.* import scala.language.higherKinds trait OptionsTests[M[_]] extends Laws { implicit def M: Monad[M] - import cats.kernel.laws._ - import discipline._ + import cats.kernel.laws.* + import discipline.* def loginEqv( email: String, diff --git a/sealedmonad/src/main/scala/pl/iterators/sealedmonad/Sealed.scala b/sealedmonad/src/main/scala/pl/iterators/sealedmonad/Sealed.scala index 1acbb03..c5efa30 100644 --- a/sealedmonad/src/main/scala/pl/iterators/sealedmonad/Sealed.scala +++ b/sealedmonad/src/main/scala/pl/iterators/sealedmonad/Sealed.scala @@ -1,12 +1,12 @@ package pl.iterators.sealedmonad -import cats._ -import cats.syntax.all._ +import cats.* +import cats.syntax.all.* import scala.Function.const sealed trait Sealed[F[_], +A, +ADT] { - import Sealed._ + import Sealed.* def map[B](f: A => B): Sealed[F, B, ADT] = Transform(this, f.andThen(left[F, B, ADT]), right[F, B, ADT]) def flatMap[B, ADT1 >: ADT](f: A => Sealed[F, B, ADT1]): Sealed[F, B, ADT1] = Transform(this, f, right[F, B, ADT1]) @@ -18,7 +18,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -38,7 +38,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -69,7 +69,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -96,7 +96,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -114,7 +114,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -138,7 +138,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -161,7 +161,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -184,7 +184,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -206,7 +206,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -229,7 +229,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -253,7 +253,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Eval * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -277,7 +277,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -296,7 +296,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -314,7 +314,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -332,7 +332,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -356,7 +356,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -380,7 +380,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -402,7 +402,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -424,7 +424,7 @@ sealed trait Sealed[F[_], +A, +ADT] { * Example: * {{{ * scala> import pl.iterators.sealedmonad.Sealed - * scala> import pl.iterators.sealedmonad.syntax._ + * scala> import pl.iterators.sealedmonad.syntax.* * scala> import cats.Id * scala> sealed trait Response * scala> case class Value(i: Int) extends Response @@ -450,7 +450,7 @@ sealed trait Sealed[F[_], +A, +ADT] { object Sealed extends SealedInstances { - import cats.syntax.either._ + import cats.syntax.either.* def apply[F[_], A](value: => F[A]): Sealed[F, A, Nothing] = defer(leftF(value)) def liftF[F[_], A](value: A): Sealed[F, A, Nothing] = defer(left(value)) @@ -464,6 +464,19 @@ object Sealed extends SealedInstances { case None => right(orElse) } + /** Shorthand for F.pure(()).seal + * + * Example: + * {{{ + * scala> import pl.iterators.sealedmonad.Sealed + * scala> import pl.iterators.sealedmonad.syntax.* + * scala> import cats.Id + * scala> Sealed.unit[Id] == Id.pure(()).seal + * res0: true + * }}} + */ + def unit[F[_]]: Sealed[F, Unit, Nothing] = liftF(()) + def valueOrF[F[_], A, ADT](fa: => F[Option[A]], orElse: => F[ADT]): Sealed[F, A, ADT] = apply(fa).flatMap { case Some(a) => left(a) diff --git a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTestInstances.scala b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTestInstances.scala index 9477b3b..8523c87 100644 --- a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTestInstances.scala +++ b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTestInstances.scala @@ -2,7 +2,7 @@ package pl.iterators.sealedmonad import cats.laws.discipline.SemigroupalTests.Isomorphisms import cats.{Eq, Monad} -import org.scalacheck._ +import org.scalacheck.* import scala.language.higherKinds diff --git a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTests.scala b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTests.scala index 91ace84..25ce883 100644 --- a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTests.scala +++ b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/SealedTests.scala @@ -1,7 +1,7 @@ package pl.iterators.sealedmonad import cats.{Eq, Monad} -import org.scalacheck.Prop._ +import org.scalacheck.Prop.* import org.scalacheck.{Arbitrary, Cogen} import org.typelevel.discipline.Laws import pl.iterators.sealedmonad.laws.SealedLaws @@ -13,7 +13,7 @@ trait SealedTests[F[_]] extends Laws with SealedTestInstances { def laws: SealedLaws[F] import SealedTestInstances.ADT - import cats.kernel.laws.discipline._ + import cats.kernel.laws.discipline.* def tests[A, B, C](implicit ArbA: Arbitrary[A], diff --git a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/laws/SealedLaws.scala b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/laws/SealedLaws.scala index 5fede94..e22bae4 100644 --- a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/laws/SealedLaws.scala +++ b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/laws/SealedLaws.scala @@ -1,7 +1,7 @@ package pl.iterators.sealedmonad.laws import cats.Monad -import cats.kernel.laws._ +import cats.kernel.laws.* import pl.iterators.sealedmonad.Sealed import pl.iterators.sealedmonad.SealedTestInstances.ADT @@ -10,9 +10,9 @@ import scala.language.higherKinds trait SealedLaws[F[_]] { implicit def M: Monad[F] - import cats.syntax.either._ - import cats.syntax.flatMap._ - import cats.syntax.functor._ + import cats.syntax.either.* + import cats.syntax.flatMap.* + import cats.syntax.functor.* def valueMapReduction[A, B](fa: F[A], f: A => B) = Sealed(fa).map(f) <-> Sealed(fa.map(f)) diff --git a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspect.scala b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspect.scala index 16f9214..44cb760 100644 --- a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspect.scala +++ b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspect.scala @@ -1,7 +1,7 @@ package pl.iterators.sealedmonad.side_effects import cats.Id -import pl.iterators.sealedmonad.syntax._ +import pl.iterators.sealedmonad.syntax.* trait SealedSideEffectsInspect { diff --git a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspectF.scala b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspectF.scala index b53f43f..dbb4347 100644 --- a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspectF.scala +++ b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsInspectF.scala @@ -1,7 +1,7 @@ package pl.iterators.sealedmonad.side_effects import cats.Eval -import pl.iterators.sealedmonad.syntax._ +import pl.iterators.sealedmonad.syntax.* trait SealedSideEffectsInspectF { diff --git a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsSemiflatTap.scala b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsSemiflatTap.scala index 0af9ee0..688d605 100644 --- a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsSemiflatTap.scala +++ b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsSemiflatTap.scala @@ -1,7 +1,7 @@ package pl.iterators.sealedmonad.side_effects import cats.{Applicative, Id} -import pl.iterators.sealedmonad.syntax._ +import pl.iterators.sealedmonad.syntax.* import cats.catsInstancesForId trait SealedSideEffectsSemiflatTap { diff --git a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsTap.scala b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsTap.scala index e6c9dbc..86d5511 100644 --- a/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsTap.scala +++ b/sealedmonad/src/test/scala/pl/iterators/sealedmonad/side_effects/SealedSideEffectsTap.scala @@ -1,7 +1,7 @@ package pl.iterators.sealedmonad.side_effects import cats.Id -import pl.iterators.sealedmonad.syntax._ +import pl.iterators.sealedmonad.syntax.* trait SealedSideEffectsTap {