Skip to content

Instantly share code, notes, and snippets.

Avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / MainMulti.scala
Created Apr 14, 2019
multi env hello world using Ciris
View MainMulti.scala
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] =
@yasuabe
yasuabe / build.sbt
Created Apr 14, 2019
sbt setting for Ciris exercise
View build.sbt
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",
@yasuabe
yasuabe / Main.scala
Created Apr 14, 2019
Hello World using Ciris
View Main.scala
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 = {
@yasuabe
yasuabe / effVer.sc
Created Apr 7, 2019
sample code for Eff
View effVer.sc
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 {
@yasuabe
yasuabe / catsMtlVer.sc
Created Apr 7, 2019
sample code for Cats MTL
View catsMtlVer.sc
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]
@yasuabe
yasuabe / monadTransformerVer.sc
Created Apr 7, 2019
sample code for monad transformer
View monadTransformerVer.sc
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)
@yasuabe
yasuabe / applicativeHandle.sc
Created Apr 7, 2019
sample code for Cats MTL ApplicativeHandle
View applicativeHandle.sc
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._
@yasuabe
yasuabe / functorRaise.sc
Created Apr 7, 2019
sample code for Cats MTL FunctorRaise
View functorRaise.sc
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 構文
@yasuabe
yasuabe / applicativeLocal.sc
Created Apr 7, 2019
sample code for Cats MTL ApplicativeLocal
View applicativeLocal.sc
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] =
@yasuabe
yasuabe / functorListen.sc
Created Apr 7, 2019
sample code for Cats MTL FunctorListen
View functorListen.sc
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]