Skip to content

Instantly share code, notes, and snippets.

Avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / accountability.sc
Created Mar 26, 2018
analysis patterns knowledge level implemented in type level programming
View accountability.sc
import shapeless.ops.coproduct.{IsCCons, Selector, Unifier}
import shapeless.{:+:, CNil, Coproduct}
// Party Types -------------------------
sealed trait PartyType
sealed trait Region extends PartyType
sealed trait Division extends PartyType
sealed trait Doctor extends PartyType
@yasuabe
yasuabe / Main.scala
Last active May 19, 2021
main for composed behavior represented in module pattern with ZIO
View Main.scala
import scalaz.zio.console.Console
import scalaz.zio._
// "org.scalaz" %% "scalaz-zio" % "1.0-RC3"
sealed trait AppError
case object NoValue extends AppError
trait Logger { val logger: Logger.Service }
object Logger {
@yasuabe
yasuabe / BalanceDemoApp.scala
Last active May 3, 2020
fs2.concurrent Balance and Broadcast demo. To run these, uncomment ConcurrentyDemoApp.
View BalanceDemoApp.scala
package qiita
import cats.effect._
import cats.syntax.functor._
import fs2.{Pipe, Stream, io, text}
import scala.concurrent.duration._
import scala.language.postfixOps
trait ConcurrencyDemoApp extends IOApp {
@yasuabe
yasuabe / iota_qiita.sc
Last active Oct 5, 2019
Iota demo. Applied to cats free monad sample.
View iota_qiita.sc
import cats.data.{State, Chain}
import cats.free.Free
import cats.~>
import iota.TListK.:::
import iota.{CopK, TNilK}
sealed trait Interact[A]
case class Ask(prompt: String) extends Interact[String]
case class Tell(msg: String) extends Interact[Unit]
@yasuabe
yasuabe / QueueTestApp.scala
Last active Sep 23, 2019
fs2 queue sample in which stdin and timer streams enqueue data and dequeuer side prints to stdout
View QueueTestApp.scala
package qiita
import cats.effect._
import cats.syntax.functor._
import fs2.concurrent.Queue
import fs2.{Pipe, Stream, io, text}
import scala.concurrent.duration._
import scala.language.postfixOps
View fs2_temperature.scala
package qiita
import java.util.concurrent.{ExecutorService, Executors}
import cats.effect._
import cats.syntax.functor._
import fs2.{Pipe, Stream, io, text}
import scala.concurrent.ExecutionContext
import scala.util.Try
@yasuabe
yasuabe / TopicDemoApp.scala
Last active Sep 22, 2019
fs2 concurrency topic demo. To run this, uncomment ConcurrencyDemoApp and package object and move them to appropriate place.
View TopicDemoApp.scala
package qiita
import fs2.concurrent.{SignallingRef, Topic}
import fs2.{INothing, io, text}
import scala.concurrent.duration._
import scala.language.postfixOps
sealed trait Event
case object Start extends Event
View pizza_transformation.scala
/*
<build.sbt>
scalaVersion := "2.13.0"
libraryDependencies ++= Seq(
"com.sksamuel.avro4s" %% "avro4s-core" % "3.0.1",
"eu.timepit" %% "refined" % "0.9.9",
"io.scalaland" %% "chimney" % "0.3.2"
)
<plugins.sbt>
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._