Skip to content

Commit

Permalink
Merge branch 'main' into update/algebra-2.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lemastero authored Nov 1, 2024
2 parents 0720797 + 8246a19 commit 740a329
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Scala CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'sbt'
- name: Run tests
run: sbt test
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name := "scala_typeclassopedia"

version := "0.0.1"

lazy val scala212 = "2.12.19"
lazy val scala213 = "2.13.14"
lazy val scala212 = "2.12.20"
lazy val scala213 = "2.13.15"

scalaVersion := scala213

Expand All @@ -14,7 +14,7 @@ resolvers += Resolver.sonatypeRepo("snapshots")
lazy val catsVersion = "2.12.0"
lazy val catsMtlVersion = "1.3.1"
lazy val scalaTestPlusVersion = "3.1.0.0-RC2"
lazy val scalacheckVersion = "1.18.0"
lazy val scalacheckVersion = "1.18.1"
libraryDependencies ++= Seq(
// cats
"org.typelevel" %% "cats-core" % catsVersion,
Expand All @@ -23,15 +23,15 @@ libraryDependencies ++= Seq(
"org.typelevel" %% "alleycats-core" % catsVersion,
"org.typelevel" %% "cats-mtl" % catsMtlVersion,
"org.typelevel" %% "cats-mtl-laws" % catsMtlVersion,
"org.typelevel" %% "cats-effect" % "3.5.2",
"org.typelevel" %% "cats-effect" % "2.5.4",

"io.monix" %% "monix" % "3.4.1",

// Scalaz
"org.scalaz" %% "scalaz-core" % "7.3.8",

// ZIO
"dev.zio" %% "zio" % "2.0.22",
"dev.zio" %% "zio" % "2.1.11",
"dev.zio" %% "zio-prelude" % "1.0.0-RC21",

// algebra
Expand All @@ -40,10 +40,10 @@ libraryDependencies ++= Seq(

// type level
"com.codecommit" %% "skolems" % "0.2.1",
"com.chuusai" %% "shapeless" % "2.3.10",
"com.chuusai" %% "shapeless" % "2.3.12",

// tofu
"tf.tofu" %% "tofu" % "0.12.1",
"tf.tofu" %% "tofu" % "0.13.6",

// izumi
"io.7mind.izumi" %% "fundamentals-bio" % "1.2.8",
Expand All @@ -56,10 +56,10 @@ libraryDependencies ++= Seq(
"org.scalatestplus" %% "scalatestplus-scalacheck" % scalaTestPlusVersion % Test,
"com.github.alexarchambault" %% "scalacheck-shapeless_1.15" % "1.3.0" % Test,

"org.scalatest" %% "scalatest" % "3.2.18" % Test,
"org.scalatest" %% "scalatest" % "3.2.19" % Test,

"org.typelevel" %% "discipline-core" % "1.7.0" % Test,
"org.typelevel" %% "discipline-scalatest" % "2.2.0" % Test
"org.typelevel" %% "discipline-scalatest" % "2.3.0" % Test
)

scalacOptions ++= Seq(
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.0
sbt.version=1.10.4
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
// sbt scalafmtAll
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
// sbt clean coverage test coverageReport
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2")
49 changes: 25 additions & 24 deletions src/test/scala/zivariant/ZivariantSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zivariant

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.must.Matchers
import zio.ZIO
import zio.{ZEnvironment, ZIO}
import zio.prelude._

class ZivariantSpec extends AnyFunSpec with Matchers with ZivariantSyntax {
Expand Down Expand Up @@ -35,8 +35,6 @@ class ZivariantSpec extends AnyFunSpec with Matchers with ZivariantSyntax {
def asDomainError: Throwable => NotFound =
err => NotFound(err.getMessage)

def idFromEmployee: EmployeeId => Int = _.v

it("bimap for function returning Either map result") {
val employee: Either[Throwable, Employee] = loadFromDb(4)

Expand All @@ -52,25 +50,28 @@ class ZivariantSpec extends AnyFunSpec with Matchers with ZivariantSyntax {
result mustBe Right("Londo Mollari")
}

it("zimap for function returning Either transform input, error channel and output") {
import Zivariant.FunctionEitherZivariant.zimap

val getEmployeeDetails: EmployeeId => Either[NotFound, String] =
zimap(idFromEmployee, asDomainError, getDetails)(loadFromDb)

val result: Either[NotFound, String] = getEmployeeDetails(EmployeeId(4))
result mustBe Right("Londo Mollari")
}

it("zimap for ZIO transform input, error channel and output") {
val loadEmployeeFromDb: ZIO[Int, Throwable, Employee] = ZIO.fromFunctionM{ id =>
ZIO.fromEither(db.get(id) match {
case Some(r) => Right(r)
case None => Left(new RuntimeException(s"Employee with id [$id] not found"))
})
}

val loadEmployee: ZIO[EmployeeId, NotFound, String] =
loadEmployeeFromDb.zimap(idFromEmployee, asDomainError, getDetails)
}
// TODO fix zivariant examples
// def idFromEmployee: ZEnvironment[EmployeeId] => ZEnvironment[Int] = ??? // a => a.map(_.v) // TODO _.v
//
// it("zimap for function returning Either transform input, error channel and output") {
// import Zivariant.FunctionEitherZivariant.zimap
//
// val getEmployeeDetails: ZEnvironment[EmployeeId] => Either[NotFound, String] =
// zimap(idFromEmployee, asDomainError, getDetails)(loadFromDb)
//
// val result: Either[NotFound, String] = getEmployeeDetails(EmployeeId(4))
// result mustBe Right("Londo Mollari")
// }
//
// it("zimap for ZIO transform input, error channel and output") {
// val loadEmployeeFromDb: ZIO[Int, Throwable, Employee] = ZIO.fromFunctionM{ id =>
// ZIO.fromEither(db.get(id) match {
// case Some(r) => Right(r)
// case None => Left(new RuntimeException(s"Employee with id [$id] not found"))
// })
// }
//
// val loadEmployee: ZIO[EmployeeId, NotFound, String] =
// loadEmployeeFromDb.zimap(idFromEmployee, asDomainError, getDetails)
// }
}

0 comments on commit 740a329

Please sign in to comment.