Last active
May 6, 2023 15:40
-
-
Save dacr/a1c04d3b8715a147223d26d8951a4026 to your computer and use it in GitHub Desktop.
ZIO learning - hello world with for comprehension / published by https://github.com/dacr/code-examples-manager #153cb6ed-f751-454b-b2d4-96c6ce45ed63/ad1b7f21c1b265ffb3cb45ef0fc3d2f9ca4efb58
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
// summary : ZIO learning - hello world with for comprehension | |
// keywords : scala, zio, learning, pure-functional, helloworld | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 153cb6ed-f751-454b-b2d4-96c6ce45ed63 | |
// created-on : 2021-03-27T17:52:36+01:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.2.2" | |
//> using dep "dev.zio::zio:2.0.13" | |
//> using dep "fr.janalyse::zio-worksheet:2.0.13.0" | |
// --------------------- | |
// ------------------------------------------------------------------------------ | |
// Inspired from Example coming from https://zio.dev/docs/getting_started.html | |
import zio.*, zio.worksheet.* | |
// -- The program value, which describes the program we want to execute | |
val logic = for { | |
_ <- Console.printLine("Hello! What is your name?") | |
name <- Console.readLine | |
_ <- Console.printLine(s"Hello, $name, welcome to ZIO!") | |
} yield () | |
// logic contains a functional effect, i.e. a data structure modelling procedural effects | |
// "Immutable data structures that model procedural effects are called functional effects" | |
// -- Let's execute our program | |
logic.unsafeRun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment