It’s time to implement the Tic-Tac-Toe application using the ZIO modules structure with ZLayer! In the following sections we are going to analyze the source code of some of the modules (the most representative ones). You can see the complete source code in the jorge-vasquez-2301/zio-zlayer-tictactoe repository.
By the way, this will be the directory structure of the project:
So, each ZIO module will be implemented as a package with a corresponding package object (the modules reflect the initial design presented above). We also have a domain package containing domain objects, and the TicTacToe main object.
We also need to add some dependencies to our build.sbt (atto is used for parsing commands):
val scalaVer = "2.13.3" val attoVersion = "0.7.2" val zioVersion = "1.0.3" lazy val compileDependencies = Seq( "dev.zio" %% "zio" % zioVersion, "dev.zio" %% "zio-macros" % zioVersion, "org.tpolecat" %% "atto-core" % attoVersion ) map (_ % Compile) lazy val testDependencies = Seq( "dev.zio" %% "zio-test" % zioVersion, "dev.zio" %% "zio-test-sbt" % zioVersion ) map (_ % Test) lazy val settings = Seq( name := "zio-zlayer-tictactoe", version := "2.0.0", scalaVersion := scalaVer, scalacOptions += "-Ymacro-annotations", libraryDependencies ++= compileDependencies ++ testDependencies, testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")) ) lazy val root = (project in file(".")) .settings(settings)
Please notice that we are working with Scala 2.13.3 and that we need to enable the -Ymacro-annotations compiler flag so that we are able to use the macros provided by the zio-macros library. If you want to work with Scala < 2.13, you’ll need to add the macro paradise compiler plugin:
compilerPlugin(("org.scalamacros" % "paradise" % "2.1.1") cross CrossVersion.full)