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)) |
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 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
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
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
import scala.language.implicitConversions | |
object CHK { | |
/* Quand on sait convertir un type | |
A dans B et réciproquement | |
*/ | |
trait Conversion[A,B] { self => | |
def to: A => B | |
def from: B => 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.language.higherKinds | |
object Toto { | |
trait Monad[M[_]] { | |
def pure[A](value: A): M[A] | |
def flatMap[A,B](ma: M[A], f: A => M[B]): M[B] | |
final def map[A,B](ma: M[A], f: A => B): M[B] = | |
flatMap(ma, f `andThen` pure) |
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
Informations de l'ordinateur : | |
Fabricant : Unknown | |
Modèle : Unknown | |
Type : Ordinateur de bureau | |
Aucun écran tactile détecté | |
Processeur : | |
Fabricant du CPU : GenuineIntel | |
Marque du processeur : Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz | |
Famille du processeur : 0x6 |
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.language.higherKinds | |
import scala.language.implicitConversions | |
import scala.util.Random | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits._ | |
/** A simple trait telling how to save in DB */ | |
sealed trait DBMode { | |
type Op[_] | |
def saveInDB[A](a: A): Op[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
(** We aim to show that the classic Reader monad is equivalent | |
to an ADT (more precisely a GADT (Generalized Algebraic Data Types). | |
*) | |
Section ForStephane. | |
(** The reader config type (what's read) | |
* | |
* trait Config | |
*) |
OlderNewer