Skip to content

Instantly share code, notes, and snippets.

import scala.io.StdIn.readLine
trait IO[+A] {
def run(): A
def flatMap[B](f: A => IO[B]): IO[B] = IO(f(run()).run())
def map[B](f: A => B): IO[B] = flatMap(a => IO(f(a)))
}
object IO {
def apply[A](a: => A): IO[A] = new IO[A] {
; Abstract methods for monadic chaining
(defprotocol Chainable
(fmap [this f])
(bind [this f]))
; Helper methods for "either" monad
(defrecord Right [value])
(defrecord Left [error])
(extend-type Right
import scalaz.zio._
import scalaz.zio.clock.Clock
import scalaz.zio.console.Console
import scalaz.zio.duration._
object KafkaClone extends App {
type Consumer[R, A] = A => ZIO[R, Nothing, _]
trait Topic[A] {
@amitayh
amitayh / BrowserE2E.scala
Created September 16, 2019 19:33
Simple example of browser E2E tests using free monad
package example
import cats.effect.IO
import cats.free.Free
import cats.free.Free.liftF
import cats.implicits._
import cats.~>
object BrowserE2E extends App {
import zio.{Promise, Ref, UIO, ZIO}
trait CountDownLatch {
def countDown: UIO[Unit]
def await: UIO[Unit]
}
object CountDownLatch {
def make(count: Int): UIO[CountDownLatch] = for {
ready <- Promise.make[Nothing, Unit]
import cats.Applicative
import cats.effect.Concurrent
import cats.effect.concurrent.{Deferred, Ref}
import cats.syntax.flatMap._
import cats.syntax.functor._
trait CountDownLatch[F[_]] {
def countDown: F[Unit]
def await: F[Unit]
}