Skip to content

Instantly share code, notes, and snippets.

View yasuabe's full-sized avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / accountability.sc
Created March 26, 2018 18:35
analysis patterns knowledge level implemented in type level programming
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 00:12
main for composed behavior represented in module pattern with ZIO
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 08:46
fs2.concurrent Balance and Broadcast demo. To run these, uncomment ConcurrentyDemoApp.
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 October 5, 2019 13:39
Iota demo. Applied to cats free monad sample.
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 September 23, 2019 12:18
fs2 queue sample in which stdin and timer streams enqueue data and dequeuer side prints to stdout
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
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 September 22, 2019 17:10
fs2 concurrency topic demo. To run this, uncomment ConcurrencyDemoApp and package object and move them to appropriate place.
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
/*
<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>
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 11:40
simple elastic4s sample using Cats Effect and Circe
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._