Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Created April 14, 2019 14:34
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 yasuabe/e7963184a539f10e84323e04758dcb31 to your computer and use it in GitHub Desktop.
Save yasuabe/e7963184a539f10e84323e04758dcb31 to your computer and use it in GitHub Desktop.
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