Skip to content

Instantly share code, notes, and snippets.

View yasuabe's full-sized avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / BracketDemo.scala
Created January 30, 2019 15:43
cats effect bracket type class demo
package cats_effect_typeclass_exericise.bracket
import java.time.format.DateTimeFormatter
import cats.MonadError
import cats.data.Kleisli
import cats.effect.ExitCase.{Canceled, Completed, Error}
import cats.effect._
import cats.effect.concurrent.Ref
import cats.syntax.either._
@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 / 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 / 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
@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
@yasuabe
yasuabe / IceCream.scala
Created January 4, 2019 05:10
refined and scalacheck
package scala_check
import scala.util.Try
import cats.syntax.either._
import cats.Apply
import cats.syntax.apply._
import shapeless.nat._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.W
import eu.timepit.refined.numeric.Interval.Closed
import cats.{Functor, Monoid, Representable}
import cats.instances.stream._
import cats.syntax.representable._
implicit val rep: Representable[Stream] { type Representation = Int } = new Representable[Stream] {
def F: Functor[Stream] = implicitly[Functor[Stream]]
type Representation = Int
def tabulate[A](f: Int => A) = {
def loop(n: Int): Stream[A] = f(n) #:: loop(n + 1)
package representable01
import cats.instances.AllInstances
import cats.laws.discipline.RepresentableTests
import cats.{Apply, Functor, Representable}
import org.scalacheck.{Arbitrary, Gen}
import org.specs2.Specification
import org.typelevel.discipline.specs2.Discipline
import cats.syntax.apply._
package representable01
import cats.instances.AllInstances
import cats.laws.discipline.RepresentableTests
import cats.{Eq, Functor, Representable}
import org.scalacheck.{Arbitrary, Gen}
import org.specs2.Specification
import org.typelevel.discipline.specs2.Discipline
import cats.instances.stream._
package adcal_1222
import adcal_1222.TupleChain.TupleChain
import cats.data.Chain
import cats.instances.AllInstances
import cats.instances.tuple._
import cats.laws.discipline.BitraverseTests
import cats.syntax.bifoldable._
import cats.syntax.bitraverse._
import cats.syntax.traverse._