Skip to content

Commit

Permalink
scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Apr 17, 2022
1 parent dd33006 commit ce672f9
Show file tree
Hide file tree
Showing 142 changed files with 2,548 additions and 2,430 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
distribution: temurin
- uses: coursier/cache-action@v6
- run: sbt -v
scalafmtSbtCheck
"+ scalafmtCheckAll"
"+ Test/compile"
"+ test"
push_gh_pages:
Expand Down
26 changes: 26 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version = "3.5.1"
runner.dialect = Scala213
maxColumn = 150
align.preset = none
align.tokens = []
rewrite.rules = [
RedundantParens
ExpandImportSelectors
PreferCurlyFors
]
rewrite.imports.contiguousGroups = "no"
rewrite.imports.groups = [[".*"]]
continuationIndent.callSite = 2
continuationIndent.defnSite = 2
docstrings.style = keep
includeCurlyBraceInSelectChains = false
optIn.breakChainOnFirstMethodDot = false
trailingCommas = preserve
newlines.topLevelStatementBlankLines = [
{
blanks { after = 1 }
maxNest = 1
regex = "Import"
}
]
project.layout = StandardConvention
45 changes: 24 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.scalajs.jsenv.nodejs._

lazy val specs2Version = Def.setting("4.15.0")
lazy val twitterUtilVersion = "22.3.0"
lazy val doobieVersion = "0.13.4"
lazy val doobieVersion = "0.13.4"

enablePlugins(BuildInfoPlugin)

Expand All @@ -24,7 +24,8 @@ dependsOn(
scalazJVM,
)

lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file("."))
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("."))
.settings(moduleName := "eff")
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings)
Expand All @@ -43,7 +44,8 @@ lazy val doobie = project
.settings(libraryDependencies ++= doobieJvm)
.settings(effSettings ++ commonJvmSettings)

lazy val catsEffect = crossProject(JVMPlatform).in(file("cats"))
lazy val catsEffect = crossProject(JVMPlatform)
.in(file("cats"))
.settings(moduleName := "eff-cats-effect")
.dependsOn(core)
.settings(
Expand All @@ -54,7 +56,8 @@ lazy val catsEffect = crossProject(JVMPlatform).in(file("cats"))

lazy val catsEffectJVM = catsEffect.jvm

lazy val macros = project.in(file("macros"))
lazy val macros = project
.in(file("macros"))
.settings(moduleName := "eff-macros")
.dependsOn(coreJVM)
.settings(libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value)
Expand All @@ -74,7 +77,8 @@ lazy val macros = project.in(file("macros"))
.settings(commonJvmSettings)
.settings(effSettings)

lazy val monix = crossProject(JSPlatform, JVMPlatform).in(file("monix"))
lazy val monix = crossProject(JSPlatform, JVMPlatform)
.in(file("monix"))
.settings(moduleName := "eff-monix")
.dependsOn(core % "test->test;compile->compile")
.settings(
Expand All @@ -85,9 +89,10 @@ lazy val monix = crossProject(JSPlatform, JVMPlatform).in(file("monix"))
.jsSettings(commonJsSettings)

lazy val monixJVM = monix.jvm
lazy val monixJS = monix.js
lazy val monixJS = monix.js

lazy val scalaz = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file("scalaz"))
lazy val scalaz = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("scalaz"))
.settings(moduleName := "eff-scalaz")
.dependsOn(core % "compile->compile;test->test")
.settings(
Expand Down Expand Up @@ -199,22 +204,21 @@ lazy val effSettings =

lazy val publishSettings =
Seq(
homepage := Some(url("https://github.com/atnos-org/eff")),
licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")),
scmInfo := Some(ScmInfo(url("https://github.com/atnos-org/eff"), "scm:git:git@github.com:atnos-org/eff.git")),
autoAPIMappings := true,
apiURL := Some(url("http://atnos.org/eff/api/")),
pomExtra := (
<developers>
homepage := Some(url("https://github.com/atnos-org/eff")),
licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")),
scmInfo := Some(ScmInfo(url("https://github.com/atnos-org/eff"), "scm:git:git@github.com:atnos-org/eff.git")),
autoAPIMappings := true,
apiURL := Some(url("http://atnos.org/eff/api/")),
pomExtra := (
<developers>
<developer>
<id>etorreborre</id>
<name>Eric Torreborre</name>
<url>https://github.com/etorreborre/</url>
</developer>
</developers>
)
) ++ credentialSettings ++ sharedPublishSettings

) ++ credentialSettings ++ sharedPublishSettings

lazy val noPublishSettings = Seq(
publish := (()),
Expand All @@ -225,7 +229,8 @@ lazy val noPublishSettings = Seq(
lazy val commonScalacOptions = Def.setting {
Seq(
"-deprecation",
"-encoding", "UTF-8",
"-encoding",
"UTF-8",
"-feature",
"-language:implicitConversions,higherKinds,existentials",
"-unchecked",
Expand Down Expand Up @@ -291,7 +296,7 @@ buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion)
buildInfoPackage := "org.atnos.eff"

lazy val warnUnusedImport = Seq(
Compile / console / scalacOptions ~= {_.filterNot("-Ywarn-unused-import" == _)},
Compile / console / scalacOptions ~= { _.filterNot("-Ywarn-unused-import" == _) },
(Test / console / scalacOptions) := (Compile / console / scalacOptions).value
)

Expand All @@ -308,9 +313,7 @@ lazy val prompt = ThisBuild / shellPrompt := { state =>
(if (name == "eff") "" else name) + "> "
}

lazy val doobieJvm = Seq(
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-h2" % doobieVersion % "test")
lazy val doobieJvm = Seq("org.tpolecat" %% "doobie-core" % doobieVersion, "org.tpolecat" %% "doobie-h2" % doobieVersion % "test")

lazy val specs2 = Def.setting(
Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import org.atnos.eff.all._
import org.atnos.eff.syntax.all._
import org.specs2._
import org.specs2.concurrent.ExecutionEnv

import org.atnos.eff._
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import IOEffect._
import org.atnos.eff.syntax.addon.cats.effect._
import scala.concurrent.duration._

class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCheck { def is = "io".title ^ sequential ^ s2"""
class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCheck {
def is = "io".title ^ sequential ^ s2"""

IO effects can work as normal values $e1
IO effects can be attempted $e2
Expand All @@ -32,7 +32,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
type S = Fx.fx2[IO, Option]

def e1 = {
def action[R :_io :_option]: Eff[R, Int] = for {
def action[R: _io: _option]: Eff[R, Int] = for {
a <- ioDelay(10)
b <- ioDelay(20)
} yield a + b
Expand All @@ -41,7 +41,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
}

def e2 = {
def action[R :_io :_option]: Eff[R, Int] = for {
def action[R: _io: _option]: Eff[R, Int] = for {
a <- ioDelay(10)
b <- ioDelay { boom; 20 }
} yield a + b
Expand All @@ -60,7 +60,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
}

def e4 = {
def action[R :_io :_option]: Eff[R, Int] = for {
def action[R: _io: _option]: Eff[R, Int] = for {
a <- ioDelay(10)
b <- ioDelay(20)
} yield a + b
Expand All @@ -71,7 +71,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
def e5 = {
val action = (1 to 5000).toList.traverseA { i =>
if (i % 5 == 0) ioDelay(i)
else ioDelay(i)
else ioDelay(i)
}

action.unsafeRunAsync(_ => ()) must not(throwA[Throwable])
Expand All @@ -80,7 +80,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
def e6 = {
var invocationsNumber = 0
val cache = ConcurrentHashMapCache()
def makeRequest = ioMemo("only once", cache, ioDelay({ invocationsNumber += 1; 1 }))
def makeRequest = ioMemo("only once", cache, ioDelay { invocationsNumber += 1; 1 })

(makeRequest >> makeRequest).unsafeRunSync must be_==(1)
invocationsNumber must be_==(1)
Expand All @@ -89,7 +89,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
def e7 = {
var invocationsNumber = 0
val cache = ConcurrentHashMapCache()
def makeRequest = ioMemo("only once", cache, ioDelay({ invocationsNumber += 1; 1 }))
def makeRequest = ioMemo("only once", cache, ioDelay { invocationsNumber += 1; 1 })

(makeRequest >> makeRequest).ioAttempt.unsafeRunSync must beRight(1)
invocationsNumber must be_==(1)
Expand All @@ -98,7 +98,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
def e8 = {
var invocationsNumber = 0
val cache = ConcurrentHashMapCache()
def makeRequest = ioMemo("only once", cache, ioDelay({ invocationsNumber += 1; 1 }))
def makeRequest = ioMemo("only once", cache, ioDelay { invocationsNumber += 1; 1 })

(makeRequest >> makeRequest).unsafeRunSync must be_==(1)
invocationsNumber must be_==(1)
Expand All @@ -108,7 +108,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
var invocationsNumber = 0
val cache = ConcurrentHashMapCache()

def makeRequest = ioDelay({ invocationsNumber += 1; 1 }).ioMemo("only once", cache)
def makeRequest = ioDelay { invocationsNumber += 1; 1 }.ioMemo("only once", cache)
(makeRequest >> makeRequest).ioAttempt.unsafeRunSync must beRight(1)

invocationsNumber must be_==(1)
Expand All @@ -122,7 +122,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh

def makeRequest =
if (firstTime)
ioMemo("only once", cache, ioDelay { firstTime = false; throw new Exception("") } >> ioDelay({ invocationsNumber += 1; 1 }))
ioMemo("only once", cache, ioDelay { firstTime = false; throw new Exception("") } >> ioDelay { invocationsNumber += 1; 1 })
else
ioMemo("only once", cache, ioDelay { invocationsNumber += 1; 1 })

Expand All @@ -139,7 +139,7 @@ class IOEffectSpec(implicit ee: ExecutionEnv) extends Specification with ScalaCh
val boomException: Throwable = new Exception("boom")

def sleepFor(duration: FiniteDuration) =
try Thread.sleep(duration.toMillis) catch { case t: Throwable => () }
try Thread.sleep(duration.toMillis)
catch { case t: Throwable => () }

}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.atnos.eff.addon.cats.effect

import cats.effect.{IO, LiftIO}
import cats.effect.IO
import cats.effect.LiftIO
import cats.effect.unsafe.IORuntime
import cats.~>
import org.atnos.eff._
import org.atnos.eff.syntax.eff._

import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration
import scala.util.Either
Expand All @@ -19,19 +19,18 @@ trait IOTypes {

}


trait IOEffectCreation extends IOTypes {

final def fromIO[R :_io, A](io: IO[A]): Eff[R, A] =
final def fromIO[R: _io, A](io: IO[A]): Eff[R, A] =
io.send[R]

final def ioRaiseError[R :_io, A](t: Throwable): Eff[R, A] =
final def ioRaiseError[R: _io, A](t: Throwable): Eff[R, A] =
IO.raiseError(t).send[R]

final def ioDelay[R :_io, A](io: =>A): Eff[R, A] =
final def ioDelay[R: _io, A](io: => A): Eff[R, A] =
IO(io).send[R]

final def ioSuspend[R :_io, A](io: =>IO[Eff[R, A]]): Eff[R, A] =
final def ioSuspend[R: _io, A](io: => IO[Eff[R, A]]): Eff[R, A] =
IO.defer(io).send[R].flatten

}
Expand Down Expand Up @@ -59,11 +58,13 @@ trait IOInterpretation extends IOTypes {

def ioAttempt[R, A](e: Eff[R, A])(implicit m: MemberInOut[IO, R]): Eff[R, Throwable Either A] = {

interpret.interceptNatM[R, IO, Either[Throwable, *], A](e,
interpret.interceptNatM[R, IO, Either[Throwable, *], A](
e,
new (IO ~> (IO of Either[Throwable, *])#l) {
def apply[X](io: IO[X]): IO[Throwable Either X] =
io.attempt
})
}
)
}

/** memoize the io result using a cache */
Expand Down Expand Up @@ -118,5 +119,3 @@ trait IOInterpretation extends IOTypes {
}

}


Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.atnos.eff.syntax.addon.cats

import cats.effect.{IO, LiftIO}
import cats.effect.IO
import cats.effect.LiftIO
import cats.effect.unsafe.IORuntime
import org.atnos.eff._
import org.atnos.eff.addon.cats.effect.{IOEffect, IOInterpretation}

import org.atnos.eff.addon.cats.effect.IOEffect
import org.atnos.eff.addon.cats.effect.IOInterpretation
import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration
import org.atnos.eff.Eff
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.atnos.eff.addon.doobie

import java.sql.Connection

import _root_.doobie.Transactor
import _root_.doobie.free.connection.ConnectionIO
import cats.effect.Bracket
Expand All @@ -22,10 +21,9 @@ trait DoobieConnectionIOCreation extends DoobieConnectionIOTypes {

trait DoobieConnectionIOInterpretation extends DoobieConnectionIOTypes {

def runConnectionIO[R, U, F[_], E, A, B](e: Eff[R, A])(t: Transactor[F])(
implicit mc: Member.Aux[ConnectionIO, R, U],
mf: F /= U,
me: Bracket[F, Throwable] ): Eff[U, A] = {
def runConnectionIO[R, U, F[_], E, A, B](
e: Eff[R, A]
)(t: Transactor[F])(implicit mc: Member.Aux[ConnectionIO, R, U], mf: F /= U, me: Bracket[F, Throwable]): Eff[U, A] = {

def getConnection: Eff[U, Connection] =
send[F, U, Connection](t.connect(t.kernel).allocated.map(_._1))
Expand Down
10 changes: 5 additions & 5 deletions doobie/src/main/scala/org/atnos/eff/syntax/addon/doobie.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import _root_.doobie.Transactor
import _root_.doobie.free.connection.ConnectionIO
import cats.effect.Bracket
import org.atnos.eff.addon.doobie._
import org.atnos.eff.{Eff, _}
import org.atnos.eff.Eff
import org.atnos.eff._

trait doobie {

Expand All @@ -14,10 +15,9 @@ trait doobie {
}

final class DoobieConnectionIOOps[R, A](private val e: Eff[R, A]) extends AnyVal {
def runConnectionIO[F[_], U, E, B](t: Transactor[F])(
implicit mc: Member.Aux[ConnectionIO, R, U],
mf: MemberInOut[F, U],
me: Bracket[F, Throwable]): Eff[U, A] = {
def runConnectionIO[F[_], U, E, B](
t: Transactor[F]
)(implicit mc: Member.Aux[ConnectionIO, R, U], mf: MemberInOut[F, U], me: Bracket[F, Throwable]): Eff[U, A] = {
DoobieConnectionIOInterpretation.runConnectionIO[R, U, F, E, A, B](e)(t)
}
}
Expand Down

0 comments on commit ce672f9

Please sign in to comment.