Skip to content

Instantly share code, notes, and snippets.

Avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / di_with_zio.sc
Last active Apr 25, 2019
dependency injection sample with ZIO
View di_with_zio.sc
import scalaz.zio.{DefaultRuntime, IO, ZIO}
// domain layer -----------------------------------------------------------
sealed trait AppError
case object NoValue extends AppError
case class Movie(id: Int, title: String)
trait MovieRepo {
def getMovie(id: Int): IO[AppError, Movie]
@yasuabe
yasuabe / DI_reader.sc
Last active Apr 23, 2019
oop to fp - reader monad
View DI_reader.sc
import cats.syntax.option._
// domain layer -----------------------------------------------------------
import monix.eval.Task
import cats.data.ReaderT
case class Movie(id: Int, title: String)
trait MovieRepo {
def getMovie(id: Int): Task[Option[Movie]]
@yasuabe
yasuabe / Main.scala
Created Apr 18, 2019
squants exercise with Circe
View Main.scala
package exercise.squants.with_circe
import eu.timepit.refined.types.string.NonEmptyString
import io.circe.parser.parse
import squants.market.{Money, Price}
import cats.syntax.either._
import io.circe.refined._
import io.circe._
import io.circe.generic.auto._
import squants.space.Volume
@yasuabe
yasuabe / Main.scala
Created Apr 18, 2019
squants exercise with pureconfig
View Main.scala
package exercise.squants.with_pureconfig
import pureconfig.ConfigReader.Result
import squants.motion.Pressure
import pureconfig.module.squants._
import pureconfig.generic.auto._
import squants.Mass
import squants.thermal._
import squants.space._
@yasuabe
yasuabe / squants_money.sc
Created Apr 18, 2019
squants exercise: Money and Price
View squants_money.sc
import squants.market.{JPY, MoneyContext, USD}
import squants.market.MoneyConversions._
val rate = USD / 112.14.yen
// r: CurrencyExchangeRate = USD/JPY 112.14
rate convert 10.dollars
// 1121.4 JPY
import squants.market.defaultMoneyContext
@yasuabe
yasuabe / squants_ex1.sc
Created Apr 18, 2019
basic usage of squants
View squants_ex1.sc
// Analysis Patterns 3.1
import squants.mass.MassConversions._
val m1 = 185 pounds
// m1: Mass = 185.0 lb
val (q, u) = m1 toTuple // 必要なら数値と単位文字列に分けることもできる
// q: Double = 185.0
// u: String = lb
import squants.market.MoneyConversions._
@yasuabe
yasuabe / build.sbt
Created Apr 18, 2019
sbt settings for squants exercise
View build.sbt
name := "squants_exercise"
version := "0.1"
scalaVersion := "2.12.8"
scalacOptions ++= Seq(
"-encoding", "utf8",
"-Xfatal-warnings",
"-Ypartial-unification",
@yasuabe
yasuabe / ciris_exercise.sc
Created Apr 14, 2019
Ciris with type safe libraries
View ciris_exercise.sc
import ciris.{ConfigKeyType, ConfigSource}
// Coproduct
import shapeless.{:+:, CNil}
import ciris.generic._
val gType = ConfigKeyType[String]("generic key")
ConfigSource.fromEntries(gType)("key" -> "5.0")
.read("key").decodeValue[Float :+: String :+: CNil].result
// Right(Inl(5.0))
@yasuabe
yasuabe / Main.scala
Created Apr 14, 2019
Ciris hello world Monix version
View Main.scala
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
@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] =