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.qiita1 | |
import ciris.api.Id | |
import ciris.{ConfigResult, env, withValues, loadConfig} | |
import ciris.generic._ | |
object MainMulti { | |
case class Config(name: String) | |
val config: ConfigResult[Id, Config] = |
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
scalaVersion := "2.12.8" | |
val cirisVersion = "0.12.1" | |
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.9") | |
scalacOptions ++= Seq( | |
"-encoding", "utf8", // Option and arguments on same line | |
"-Xfatal-warnings", // New lines for each options | |
"-Ypartial-unification", |
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.qiita1 | |
import ciris.api.Id | |
import ciris.{ConfigEntry, ConfigErrors, ConfigResult, env, loadConfig, file} | |
import ciris.generic._ | |
case class Config(name: String) | |
object Main { | |
def main(args: Array[String]): Unit = { |
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
import cats.data.State | |
import org.atnos.eff._ | |
import org.atnos.eff.all._ | |
import org.atnos.eff.syntax.all._ | |
object E { | |
type _eitherString[R] = Either[String, ?] |= R | |
type _stateInt[R] = State[Int, ?] |= R | |
def decr[R: _eitherString: _stateInt]: Eff[R, Unit] = for { |
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
import cats.data.{EitherT, State, StateT} | |
import cats.Monad | |
import cats.syntax.flatMap._ | |
import cats.syntax.functor._ | |
import cats.instances.either._ | |
import cats.mtl.{FunctorRaise, MonadState} | |
import MonadState._ | |
import FunctorRaise._ | |
type MSI[F[_]] = MonadState[F, Int] |
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
import cats.data.{EitherT, State, StateT} | |
import cats.instances.either._ | |
object A { | |
type SET[E, S, R] = StateT[Either[E, ?], S, R] | |
type EST[E, S, R] = EitherT[State[S, ?], E, R] | |
def decrementSE: SET[String, Int, Unit] = for { | |
x <- StateT.get[Either[String, ?], Int] | |
_ <- if (x > 0) StateT.set[Either[String, ?], Int](x - 1) |
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
import cats.syntax.applicative._ | |
import cats.Applicative | |
import cats.data.Validated | |
import cats.instances.string._ | |
import cats.mtl.FunctorRaise | |
import cats.mtl.syntax.handle._ | |
import cats.mtl.instances.handle._ | |
import cats.syntax.traverse._ | |
import cats.instances.list._ |
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
import cats.mtl.FunctorRaise | |
import cats.syntax.applicative._ | |
import cats.instances.string._ | |
import cats.{Applicative, Semigroupal} | |
import cats.data.Validated | |
def parseNumber[F[_]: Applicative](in: String)(implicit F: FunctorRaise[F, String]): F[Double] = | |
if (in.matches("-?[0-9]+")) in.toDouble.pure[F] | |
else F.raise(in) // raise 構文 |
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
import cats.data.ReaderT | |
import cats.effect.IO | |
import cats.syntax.flatMap._ | |
import cats.syntax.functor._ | |
import cats.{Applicative, Monad} | |
import cats.mtl.{ApplicativeAsk, ApplicativeLocal} | |
type Config = Map[String, String] | |
def get42[F[_]: Applicative](implicit F: ApplicativeAsk[F, Config]): F[String] = |
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
import cats.{FlatMap, Monad} | |
import cats.data.{Chain, WriterT} | |
import cats.effect.{IO, Sync} | |
import cats.syntax.flatMap._ | |
import cats.syntax.functor._ | |
import cats.mtl.syntax.listen._ | |
import cats.mtl.{FunctorListen, FunctorTell} | |
import Chain.one | |
type Logs = Chain[String] |