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
trait Stream[A] { self => | |
def head : A | |
def tail : Stream[A] | |
def map[B](f : A => B) : Stream[B] = new Stream[B] { | |
val head = f(self.head) | |
lazy val tail = self.tail.map(f) | |
} | |
def extend[B](f : Stream[A] => B) : Stream[B] = new Stream[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
trait NaturalTransformation[F[_], G[_]] { | |
import cats.syntax.eq._ | |
import cats.Functor | |
implicit val F : Functor[F] | |
implicit val G : Functor[G] | |
def apply[A](fa : F[A]) : G[A] | |
/** For an implementation to be valid, this function must |
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 SimpleGeneralizedZipper { | |
sealed abstract class Direction | |
final case object Haut extends Direction | |
final case object Gauche extends Direction | |
final case object Droite extends Direction | |
sealed abstract class Stream[-I, +A] { | |
def focus : A | |
def cont : I => Stream[I, 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
object FreeMonadExample { | |
import scala.language.higherKinds | |
/** The Functor type class */ | |
trait Functor[F[_]] { | |
def map[A,B](fa : F[A])(f : A => B) : F[B] | |
} | |
implicit final class FunctorOps[F[_],A](val self : F[A]) extends AnyVal { |
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 StackTest { | |
def main(args : Array[String]) : Unit = { | |
val f1 = (1 to 100000).foldLeft(ComposeQueue(identity[Int])) { (f, _) => f.andThen(_ + 1) } | |
println(f1(0)) | |
val f2 = (1 to 1000000).foldLeft(ComposeQueue(identity[Int])){ (f, _) => f.andThen(_ + 1) } | |
println(f2(0)) | |
val f3 = (1 to 1000000).foldLeft(ComposeQueue(identity[Int])) { (f, _) => f.compose(_ + 1) } | |
println(f3(0)) |
NewerOlder