Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active June 24, 2023 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/90aabb842e1d993a65b378238ba31c92 to your computer and use it in GitHub Desktop.
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/5be89893b89dccf3fb04e34c40d77cc385b8dd89
// 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.3.0"
//> 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