This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
import cats.effect.IO | |
import cats.free.Free | |
import cats.free.Free.liftF | |
import cats.implicits._ | |
import cats.~> | |
object BrowserE2E extends App { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Node(value: Int, | |
left: Option[Node] = None, | |
right: Option[Node] = None) | |
object Serializer { | |
private val pattern = """^(\d+)\((.*)\)$""".r | |
private val treeOpen = '(' | |
private val treeClose = ')' | |
private val separator = ',' | |
private val separatorLength = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wixpress.quotes.common | |
import java.util.UUID | |
object CQRS { | |
//////////////////////////////////////////////////////////////////////////////// | |
// Example application | |
//////////////////////////////////////////////////////////////////////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function * permutations(str) { | |
var length = str.length; | |
if (length <= 1) { | |
yield str; | |
} else { | |
for (var i = 0; i < length; i++) { | |
var ch = str[i], substr = str.substr(0, i) + str.substr(i + 1); | |
for (var permutation of permutations(substr)) { | |
yield ch + permutation; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function match($string, $pattern) { | |
$automata = new Automata($pattern); | |
return $automata->match($string); | |
} | |
function get_chars($string) { | |
for ($i = 0; $i < strlen($string); $i++) { | |
yield $string[$i]; |
NewerOlder