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