Last active
May 25, 2024 08:38
-
-
Save dacr/90aabb842e1d993a65b378238ba31c92 to your computer and use it in GitHub Desktop.
First use of cats-effect API. / published by https://github.com/dacr/code-examples-manager #29b448c8-33f7-45d1-b578-930284dee3aa/97f65e0df31db3c4a461842a70f4ed696f1be80f
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 : First use of cats-effect API. | |
// keywords : scala, cats, effect | |
// 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 : 29b448c8-33f7-45d1-b578-930284dee3aa | |
// created-on : 2019-06-26T19:37:50Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "org.typelevel::cats-effect:3.5.0" | |
// --------------------- | |
import cats._ | |
import cats.data._ | |
import cats.implicits._ | |
import cats.effect.IO | |
import cats.effect.unsafe.implicits.global | |
// example inspired from https://alvinalexander.com/scala/cats-io-monad-sbt-example-app | |
val program = for { | |
_ <- IO { println("Welcome to Scala! What's your name?") } | |
name <- IO { scala.io.StdIn.readLine } | |
_ <- IO { println(s"Well hello, $name!") } | |
} yield () | |
program.unsafeRunSync() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment