Skip to content
Open
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
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.2
48 changes: 48 additions & 0 deletions zio/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.4.2"

scalacOptions ++= Seq(
"-encoding", "utf8",
"-unchecked",
"-deprecation",
"-feature",
"-Ykind-projector",
"-Wunused:imports,privates,params,locals,implicits,explicits",
"-Wvalue-discard",
"-Wnonunit-statement"
)

Test / scalacOptions --= Seq(
"-Wnonunit-statement" // does not work with assertions in scalatest, which always return an Assertion
)

fork in Global := true

val versions = new {
val scalatestVersion = "3.2.18"
}

lazy val zioVersion = "2.0.0"

lazy val root = (project in file("."))
.settings(
name := "zio-kata",
libraryDependencies ++= Seq(
// Logging
"ch.qos.logback" % "logback-classic" % "1.5.6",
"org.typelevel" %% "log4cats-slf4j" % "2.6.0",

// ZIO
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion,
"dev.zio" %% "zio-test-sbt" % zioVersion,
"dev.zio" %% "zio-streams" % zioVersion,
"dev.zio" %% "zio-test-junit" % zioVersion,
"dev.zio" %% "zio-http" % "3.0.0-RC6",

// Test
"org.scalactic" %% "scalactic" % versions.scalatestVersion % Test,
"org.scalatest" %% "scalatest" % versions.scalatestVersion % Test
)
)
7 changes: 7 additions & 0 deletions zio/project/.scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.3")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

addSbtPlugin("nl.gn0s1s" % "sbt-dotenv" % "3.0.0")
1 change: 1 addition & 0 deletions zio/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.6
36 changes: 36 additions & 0 deletions zio/src/main/scala/Effects.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

//local reasoning = describe the entire of computation that would be perform
//referential transparency = replace a program with the value it evaluates too as many times as we like
// if replacing an expression with the value it evaluates change the behavior then it break referential transparency


//we would like to write pure program but at the same time side efect are inevitable

//we would like to have some data structure that bridge the concept of side effect with the concept of ref transparency and local reasoning
// Effect => it should describe the computation, the kind of value it produces
// => we want to separate the construction from the execution, if side effect are require

// Is an Option an effect ?
// Example val anOption: Option[Int] = Option(10)
// Option is an effect (no side effect and validate the properties)

// Is Future an effect ?
// Does it describe computation ?
// Yes there is a side effect bc we need to schedule the computation on a JVM thread
// Future is not an effect


object Effects extends App {

// functional programming
// EXPRESSIONS
def combine(a: Int, b: Int): Int = a + b

// local reasoning = type signature describes the kind of computation that will be performed
// referential transparency = ability to replace an expression with the value that it evaluates to
val five = combine(2, 3)
val five_v2 = 2 + 3
val five_v3 = 5

println(five)
}
21 changes: 21 additions & 0 deletions zio/src/main/scala/Zio.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import zio._


object ZIOEffects extends App{

// success
val meaningOfLife: ZIO[Any, Nothing, Int] = ZIO.succeed(42)
// failure
val aFailure: ZIO[Any, String, Nothing] = ZIO.fail("Something went wrong")
// suspension/delay
val aSuspendedZIO: ZIO[Any, Throwable, Int] = ZIO.suspend(meaningOfLife)


case class MyIO[A](unsafeRun: () => A) {
def map[B](f: A => B): MyIO[B] = ???

def flatMap[B](f: A => MyIO[B]): MyIO[B] = ???
}


}
11 changes: 11 additions & 0 deletions zio/src/test/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import zio._
import zio.test._

object firstEffectTest extends ZIOSpecDefault {
def spec = test("first effect test"){
val person = ZIO.succeed("Test")
assertZIO(person)(Assertion.equalTo("Test"))
}
}