Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy cleanup #247

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.19, 2.13.14, 3.3.3]
scala: [2.13.15, 3.3.3]
java: [temurin@8, temurin@17]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -61,4 +61,4 @@ jobs:
with:
fetch-depth: 0
- uses: olafurpg/setup-scala@v13
- run: sbt '++2.12.18; docs/mdoc'
- run: sbt '++2.13.15; docs/mdoc'
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class SingleSealedOps {
}

@Benchmark
def attemptFBenchmark = Sealed.liftF(x).attemptF(attemptFWork).map(Ok).run
def attemptFBenchmark = Sealed.liftF(x).attemptF(attemptFWork).map(Ok.apply).run

@Benchmark
def attemptFCatsBaseline = EitherT.rightT[Try, ADT](x).flatMapF(attemptFWork).map(Ok).value
def attemptFCatsBaseline = EitherT.rightT[Try, ADT](x).flatMapF(attemptFWork).map(Ok.apply).value
}
80 changes: 51 additions & 29 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
val isDotty = Def.setting(CrossVersion.partialVersion(scalaVersion.value).exists(_._1 != 2))
val isScala3 = Def.setting(CrossVersion.partialVersion(scalaVersion.value).exists(_._1 != 2))

// Dependencies

val catsVersion = "2.12.0"
val castsTestkitScalatestVersion = "2.1.5"

libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % catsVersion,
"org.typelevel" %% "cats-laws" % catsVersion % Test,
"org.typelevel" %% "cats-testkit" % catsVersion % Test,
"org.typelevel" %% "cats-testkit-scalatest" % castsTestkitScalatestVersion % Test
)

libraryDependencies ++= (if (isDotty.value) Nil
else
Seq(compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full)))
val scalatestVersion = "3.2.19"
val disciplineVersion = "2.3.0"

// Multiple Scala versions support

val scala_2_12 = "2.12.19"
val scala_2_13 = "2.13.14"
val dotty = "3.3.1"
val scala_2_13 = "2.13.15"
val scala_3 = "3.3.3"
val mainScalaVersion = scala_2_13
val supportedScalaVersions = Seq(scala_2_12, scala_2_13, dotty)
val supportedScalaVersions = Seq(scala_2_13, scala_3)

ThisBuild / crossScalaVersions := supportedScalaVersions
ThisBuild / scalaVersion := mainScalaVersion

lazy val baseSettings = Seq(
// Scala settings
homepage := Some(url("https://github.com/theiterators/sealed-monad")),
scalacOptions := Seq("-deprecation", "-unchecked", "-feature", "-encoding", "utf8") ++
(if (isDotty.value)
Seq("-language:implicitConversions", "-Ykind-projector", "-Xignore-scala2-macros")
else Nil),
scalacOptions ++= (if (isScala3.value)
Seq(
"-deprecation",
"-unchecked",
"-feature",
"-language:implicitConversions",
"-Ykind-projector:underscores",
"-encoding",
"utf8"
)
else
Seq(
"-deprecation",
"-unchecked",
"-feature",
"-Xsource:3",
"-P:kind-projector:underscore-placeholders",
"-encoding",
"utf8"
)),
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % catsVersion,
"org.typelevel" %%% "cats-laws" % catsVersion % Test,
"org.typelevel" %%% "cats-testkit" % catsVersion % Test,
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.typelevel" %%% "discipline-scalatest" % disciplineVersion % Test
) ++ (if (isScala3.value) Nil
else
Seq(compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full))),
scalafmtOnCompile := true,
// Sonatype settings
sonatypeProfileName := "pl.iterators",
Expand All @@ -43,10 +58,10 @@ lazy val baseSettings = Seq(
organizationHomepage := Some(url("https://www.iteratorshq.com")),
developers := List(
Developer(
id = "mrzeznicki",
name = "Marcin Rzeźnicki",
email = "[email protected]",
url = url("https://github.com/marcin-rzeznicki")
id = "luksow",
name = "Łukasz Sowa",
email = "[email protected]",
url = url("https://github.com/luksow")
),
Developer(
id = "pkiersznowski",
Expand All @@ -72,7 +87,7 @@ lazy val noPublishSettings =

lazy val examples = project
.in(file("examples"))
.dependsOn(sealedMonad % "test->test;compile->compile")
.dependsOn(sealedMonad.jvm % "test->test;compile->compile")
.settings(baseSettings: _*)
.settings(noPublishSettings: _*)
.settings(
Expand All @@ -83,7 +98,7 @@ lazy val examples = project

lazy val docs = project
.in(file("sealed-docs"))
.dependsOn(sealedMonad % "test->test;compile->compile")
.dependsOn(sealedMonad.jvm % "test->test;compile->compile")
.enablePlugins(MdocPlugin, DocusaurusPlugin)
.settings(baseSettings: _*)
.settings(noPublishSettings: _*)
Expand All @@ -100,7 +115,7 @@ lazy val docs = project

lazy val benchmarks = project
.in(file("benchmarks"))
.dependsOn(sealedMonad % "test->test;compile->compile")
.dependsOn(sealedMonad.jvm % "test->test;compile->compile")
.enablePlugins(JmhPlugin)
.settings(baseSettings: _*)
.settings(noPublishSettings: _*)
Expand All @@ -112,10 +127,17 @@ lazy val benchmarks = project

addCommandAlias("flame", "benchmarks/jmh:run -p tokens=64 -prof jmh.extras.Async:dir=target/flamegraphs;flameGraphOpts=--width,1900")

lazy val sealedMonad = project
.in(file("."))
lazy val sealedMonad = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("sealedmonad"))
.jsConfigure(_.disablePlugins(DoctestPlugin))
.settings(baseSettings: _*)
.settings(
name := "sealed-monad",
description := "Scala library for nice for-comprehension-style error handling"
)

// lazy val root = project
// .in(file("."))
// .aggregate(sealedMonad.jvm, sealedMonad.js, sealedMonad.native, examples, docs, benchmarks)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package pl.iterators.sealedmonad.examples
import cats.{Eq, Monad}
import org.scalacheck.{Arbitrary, Cogen}
import Options._
import org.typelevel.discipline.Laws
import org.scalacheck.Prop

import scala.language.higherKinds

Expand All @@ -21,10 +23,10 @@ trait AllTests[M[_]] extends OptionsTests[M] {
EqMLogResp: Eq[M[LoginResponse]],
EqMConfirmResp: Eq[M[ConfirmResponse]]
) = new RuleSet {
override val name = "all"
override val bases = Seq.empty
override val parents = Seq(options)
override val props = Seq.empty
override val name = "all"
override val bases: Seq[(String, Laws#RuleSet)] = Seq.empty
override val parents: Seq[RuleSet] = Seq(options)
override val props: Seq[(String, Prop)] = Seq.empty
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package pl.iterators.sealedmonad.examples

import cats.Eq
import cats.tests.CatsSuite
import org.scalacheck.{Arbitrary, Gen}
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Seconds, Span}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.scalacheck.Checkers
import org.typelevel.discipline.scalatest.FunSuiteDiscipline

import scala.concurrent.{ExecutionContext, Future}

trait ExamplesSuite extends CatsSuite with ScalaFutures {
trait ExamplesSuite extends AnyFunSuite with FunSuiteDiscipline with Checkers with ScalaFutures {
implicit final val executionContext: ExecutionContext = ExecutionContext.global
override implicit final val patienceConfig: PatienceConfig = super.patienceConfig.copy(timeout = scaled(Span(4, Seconds)))

Expand Down
5 changes: 5 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("com.github.tkawachi" % "sbt-doctest" % "0.10.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.4")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.4")
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,13 @@ object Sealed extends SealedInstances {
}
}

private final class SealedMonad[F[_], ADT] extends StackSafeMonad[Sealed[F, *, ADT]] {
override def pure[A](x: A) = Sealed.liftF(x)
override def flatMap[A, B](fa: Sealed[F, A, ADT])(f: A => Sealed[F, B, ADT]) = fa.flatMap(f)
override def map[A, B](fa: Sealed[F, A, ADT])(f: A => B) = fa.map(f)
override def widen[A, B >: A](fa: Sealed[F, A, ADT]) = fa
private final class SealedMonad[F[_], ADT] extends StackSafeMonad[Sealed[F, _, ADT]] {
override def pure[A](x: A): Sealed[F, A, ADT] = Sealed.liftF(x)
override def flatMap[A, B](fa: Sealed[F, A, ADT])(f: A => Sealed[F, B, ADT]): Sealed[F, B, ADT] = fa.flatMap(f)
override def map[A, B](fa: Sealed[F, A, ADT])(f: A => B): Sealed[F, B, ADT] = fa.map(f)
override def widen[A, B >: A](fa: Sealed[F, A, ADT]): Sealed[F, B, ADT] = fa
}

trait SealedInstances {
implicit def sealedMonad[F[_], ADT]: Monad[Sealed[F, *, ADT]] = new SealedMonad
implicit def sealedMonad[F[_], ADT]: Monad[Sealed[F, _, ADT]] = new SealedMonad
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pl.iterators.sealedmonad

import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.scalacheck.Checkers
import org.typelevel.discipline.scalatest.FunSuiteDiscipline

abstract class SealedSuite extends AnyFunSuite with FunSuiteDiscipline with Checkers with SealedTestInstances
5 changes: 0 additions & 5 deletions src/test/scala/pl/iterators/sealedmonad/SealedSuite.scala

This file was deleted.

Loading