Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated ZIO modules to the new simplified version (#193)
- Loading branch information
Showing
8 changed files
with
72 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 8 additions & 17 deletions
25
blinky-cli/src/main/scala/blinky/run/modules/CliModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,21 @@ | ||
package blinky.run.modules | ||
|
||
import better.files.File | ||
import zio.ZIO | ||
|
||
trait CliModule { | ||
def cliModule: CliModule.Service[Any] | ||
} | ||
import zio.{Layer, ZIO, ZLayer} | ||
|
||
object CliModule { | ||
|
||
trait Service[R] { | ||
def pwd: ZIO[R, Nothing, File] | ||
trait Service { | ||
def pwd: ZIO[Any, Nothing, File] | ||
} | ||
|
||
trait Live extends CliModule { | ||
val pwdLive: File | ||
def pwd: ZIO[CliModule, Nothing, File] = | ||
ZIO.accessM[CliModule](_.get.pwd) | ||
|
||
override val cliModule: Service[Any] = new Service[Any] { | ||
def live(pwdLive: File): Layer[Nothing, CliModule] = | ||
ZLayer.succeed(new Service { | ||
override def pwd: ZIO[Any, Nothing, File] = | ||
ZIO.succeed(pwdLive) | ||
} | ||
} | ||
|
||
object factory extends CliModule.Service[CliModule] { | ||
override def pwd: ZIO[CliModule, Nothing, File] = | ||
ZIO.accessM[CliModule](_.cliModule.pwd) | ||
} | ||
}) | ||
|
||
} |
28 changes: 10 additions & 18 deletions
28
blinky-cli/src/main/scala/blinky/run/modules/ExternalModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
package blinky.run.modules | ||
|
||
import blinky.run.external.{AmmoniteExternalCalls, ExternalCalls} | ||
import zio.ZIO | ||
|
||
trait ExternalModule { | ||
def externalModule: ExternalModule.Service[Any] | ||
} | ||
import zio.{Layer, ZIO, ZLayer} | ||
|
||
object ExternalModule { | ||
|
||
trait Service[R] { | ||
def external: ZIO[R, Nothing, ExternalCalls] | ||
trait Service { | ||
def external: ZIO[Any, Nothing, ExternalCalls] | ||
} | ||
|
||
trait Live extends ExternalModule { | ||
override def externalModule: Service[Any] = | ||
new Service[Any] { | ||
override def external: ZIO[Any, Nothing, ExternalCalls] = | ||
ZIO.succeed(AmmoniteExternalCalls) | ||
} | ||
} | ||
def external: ZIO[ExternalModule, Nothing, ExternalCalls] = | ||
ZIO.accessM[ExternalModule](_.get.external) | ||
|
||
object factory extends ExternalModule.Service[ExternalModule] { | ||
override def external: ZIO[ExternalModule, Nothing, ExternalCalls] = | ||
ZIO.accessM[ExternalModule](_.externalModule.external) | ||
} | ||
val live: Layer[Nothing, ExternalModule] = | ||
ZLayer.succeed(new Service { | ||
override def external: ZIO[Any, Nothing, ExternalCalls] = | ||
ZIO.succeed(AmmoniteExternalCalls) | ||
}) | ||
|
||
} |
28 changes: 10 additions & 18 deletions
28
blinky-cli/src/main/scala/blinky/run/modules/ParserModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
package blinky.run.modules | ||
|
||
import scopt.{DefaultOParserSetup, OParserSetup} | ||
import zio.ZIO | ||
|
||
trait ParserModule { | ||
def parserModule: ParserModule.Service[Any] | ||
} | ||
import zio.{Layer, ZIO, ZLayer} | ||
|
||
object ParserModule { | ||
|
||
trait Service[R] { | ||
def parser: ZIO[R, Nothing, OParserSetup] | ||
trait Service { | ||
def parser: ZIO[Any, Nothing, OParserSetup] | ||
} | ||
|
||
trait Live extends ParserModule { | ||
override def parserModule: Service[Any] = | ||
new Service[Any] { | ||
override def parser: ZIO[Any, Nothing, OParserSetup] = | ||
ZIO.succeed(new DefaultOParserSetup() {}) | ||
} | ||
} | ||
def parser: ZIO[ParserModule, Nothing, OParserSetup] = | ||
ZIO.accessM[ParserModule](_.get.parser) | ||
|
||
object factory extends ParserModule.Service[ParserModule] { | ||
override def parser: ZIO[ParserModule, Nothing, OParserSetup] = | ||
ZIO.accessM[ParserModule](_.parserModule.parser) | ||
} | ||
val live: Layer[Nothing, ParserModule] = | ||
ZLayer.succeed(new Service { | ||
override def parser: ZIO[Any, Nothing, OParserSetup] = | ||
ZIO.succeed(new DefaultOParserSetup() {}) | ||
}) | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
blinky-cli/src/main/scala/blinky/run/modules/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package blinky.run | ||
|
||
import zio.Has | ||
|
||
package object modules { | ||
|
||
type ParserModule = Has[ParserModule.Service] | ||
|
||
type CliModule = Has[CliModule.Service] | ||
|
||
type ExternalModule = Has[ExternalModule.Service] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters