Last active
February 3, 2026 20:25
-
-
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/2cf1a7d4d0d61d1035b5cf1711146a3f3f21c94e
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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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