Last active
September 28, 2024 08:58
-
-
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/cf30ec67a2941ece6bd2424125a15ff46ca3c2fd
This file contains hidden or 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.5.1" | |
//> using dep "org.typelevel::cats-effect:3.5.4" | |
// --------------------- | |
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