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
endpoint.errorOut( oneOf[String]( | |
statusMapping(StatusCode.Unauthorized, stringBody), | |
statusMapping(StatusCode.BadRequest, stringBody) ) ) |
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
endpoint.errorOut(statusCode(StatusCode.Unauthorized).and(stringBody)) |
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
package ioleo.tictactoe | |
import ioleo.tictactoe.domain.State | |
import zio.{console, App, UIO, ZIO} | |
object TicTacToe extends App { | |
val program = { | |
def loop(state: State): ZIO[app.RunLoop, Nothing, Unit] = | |
app.RunLoop.>.step(state).foldM( |
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
package ioleo.tictactoe | |
import ioleo.tictactoe.app.RunLoop | |
import ioleo.tictactoe.domain.{ConfirmAction, ConfirmMessage, MenuMessage, State} | |
import zio.{Managed, ZIO} | |
import zio.clock.Clock | |
import zio.duration._ | |
import zio.test.{assertM, suite, testM, DefaultRunnableSpec} | |
import zio.test.Assertion.{equalTo, isRight, isSome, isUnit} | |
import zio.test.mock.Expectation.{failure, value} |
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
import zio.test.mock.{Method, Mock, Mockable} | |
object MockConsole { | |
// ... | |
object putStr extends Method[MockConsole, String, Unit] | |
object putStrLn extends Method[MockConsole, String, Unit] | |
object getStrLn extends Method[MockConsole, Unit, String] | |
implicit val mockable: Mockable[MockConsole] = (mock: Mock) => |
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
import zio.test.mock.Expectation.{unit, value} | |
val mock: Managed[Nothing, MockConsole] = ( | |
(MockConsole.getStrLn returns value("first")) *> | |
(MockConsole.getStrLn returns value("second")) *> | |
(MockConsole.putStrLn(equalTo("first & second")) returns unit) | |
) |
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
package ioleo.tictactoe.cli | |
import zio.Managed | |
import zio.test.{assertM, checkM, suite, testM, DefaultRunnableSpec, Gen} | |
import zio.test.Assertion.equalTo | |
import zio.test.mock.Expectation.value | |
import zio.test.mock.MockConsole | |
import TerminalSpecUtils._ |
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
package ioleo.tictactoe.cli | |
import zio.console.Console | |
trait TerminalLive extends Terminal { | |
val console: Console.Service[Any] | |
final val terminal = new Terminal.Service[Any] { |
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
package ioleo.tictactoe.cli | |
import zio.ZIO | |
import zio.macros.annotation.{accessible, mockable} | |
@accessible(">") | |
@mockable | |
trait Terminal { | |
val terminal: Terminal.Service[Any] |
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
def parse(input: String): UIO[MenuCommand] = | |
UIO.succeed(input) map { | |
case "new game" => MenuCommand.NewGame | |
case "resume" => MenuCommand.Resume | |
case "quit" => MenuCommand.Quit | |
case _ => MenuCommand.Invalid | |
} |