Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Created Apr 14, 2019
Embed
What would you like to do?
Ciris hello world Monix version
package exercise.ciris.qiita3
import cats.effect.ExitCode.{Error, Success}
import cats.effect.{ExitCode, Sync}
import cats.syntax.functor._
import ciris.api.{Apply => CApply}
import ciris.cats.effect._
import ciris.{envF, loadConfig}
import monix.eval.{Task, TaskApp}
import scala.language.higherKinds
case class Config(name: String)
object Main extends TaskApp {
def config[F[_]: CApply] = loadConfig(envF[F, String]("NAME"))(Config)
def program[F[_]: Sync](c: Config) = Sync[F].delay { println(s"Hello, ${c.name}!") }
def run(args: List[String]): Task[ExitCode] = for {
r <- config[Task].result
x <- r.fold(
e => Task(println(e.message)) as Error,
c => program[Task](c) as Success
)
} yield x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment