Skip to content

Instantly share code, notes, and snippets.

Avatar

Yasuyuki Abe yasuabe

View GitHub Profile
View prime-stream-with-cats-pairingheap.sc
import cats.Order
import cats.collections.PairingHeap
import cats.instances.long._
import PairingHeap.empty
type Longs = Stream[Long]
implicit val x: Order[Longs] = (x, y) => x.head compare y.head
def spin(start: Long, wheel: Longs): Longs = {
def cycle(ns: Longs): Longs = ns append cycle(ns)
@yasuabe
yasuabe / ArtistIndex.scala
Created May 10, 2019
simple elastic4s sample using Cats Effect and Circe
View ArtistIndex.scala
package trial1
import cats.effect._
import cats.instances.list._
import cats.syntax.flatMap._
import cats.syntax.functor._
import cats.syntax.traverse._
import com.sksamuel.elastic4s.circe._
import com.sksamuel.elastic4s.http.search.SearchResponse
import com.sksamuel.elastic4s.http._
@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 / 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