This file contains 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
object Monads { | |
trait Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Monad[M[_]] extends Functor[M] { | |
self => | |
def unit[A](a: => A): M[A] |
This file contains 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.xml.pull._ | |
import scalaz._ | |
import Scalaz._ | |
trait Input[F[_]] { | |
type =>>[A, B] = StateT[Option, F[A], B] | |
def uncons[A](f: F[A]): Option[(F[A], A)] | |
def next[A]: (A =>> A) = StateT { uncons } | |
def none[A, B] = Option.empty[(F[A], B)] |
This file contains 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 java.util.Optional; | |
import java.util.function.BiFunction; | |
import java.util.function.Function; | |
// Profunctor Optics | |
// http://programming-journal.org/2017/1/7/ | |
public interface Optics { | |
static void main(final String[] args) { | |
System.out.println(Pair.<String, Optional<Pair<Integer, Boolean>>> |
This file contains 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._ | |
import cats.implicits._ | |
import scala.annotation.tailrec | |
import scala.util.control.TailCalls._ | |
/* | |
http://okmij.org/ftp/continuations/zipper.html | |
http://okmij.org/ftp/Haskell/ZipperTraversable.hs | |
*/ |
This file contains 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.annotation.tailrec | |
import Thunk._ | |
/* | |
https://www.cs.utah.edu/~mflatt/past-courses/cs6520/public_html/s02/cps.pdf | |
*/ | |
sealed trait Thunk[A, B] { | |
@inline final def run(f: A => B): B = Thunk.run(this, f) | |
} |
This file contains 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 sandbox | |
import scala.annotation.tailrec | |
import scala.util.continuations.{cps, _} | |
/* | |
Introduction to Programming with Shift and Reset | |
http://pllab.is.ocha.ac.jp/~asai/cw2011tutorial/main-e.pdf | |
*/ |
This file contains 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 org.parboiled2._ | |
/* | |
http://okmij.org/ftp/tagless-final/course/lecture.pdf | |
*/ | |
object Tagless extends scala.App { | |
type Id[A] = A | |
trait ~>[F[_], G[_]] { |
This file contains 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 Cont._ | |
object ContTest extends App { | |
def fib() = loop(for { | |
(x, y) <- take[(BigInt, BigInt), Stream[BigInt]] | |
_ <- put(x) | |
} yield (y, x + y))(1, 1) | |
println(fib().take(100).toList) |
This file contains 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
/* | |
https://github.com/rizo/streams/blob/master/src/coroutine.ml | |
https://pusher.com/sessions/meetup/the-realtime-guild/realtime-stream-processing-with-coroutines | |
*/ | |
object Pipes { | |
sealed trait Pipe[I, O, R] { | |
final def flatMap[T](f: R => Pipe[I, O, T]): Pipe[I, O, T] = this match { |
This file contains 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
// Faster coroutine pipelines | |
// https://dl.acm.org/citation.cfm?doid=3136534.3110249 | |
// https://github.com/iokasimov/pipeline/blob/master/Control/Pipeline.hs | |
object Monads { | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] | |
def >>=[A, B](m: M[A])(f: A => M[B]): M[B] |
OlderNewer