Skip to content

Instantly share code, notes, and snippets.

Christophe Calvès chrilves

Block or report user

Report or block chrilves

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View validation-cheat-sheet.scala
import $ivy.`io.github.jto:validation-xml_2.12:2.1.1`
import jto.validation._
import jto.validation.xml._
import jto.validation.xml.Rules._
import scala.xml._
import scala.reflect.runtime.universe._
final case class Test(x: Int, y: Int)
implicit val testR: Rule[Node, Test] =
View Wild_exposed_as_a_GADT.scala
/* Modified version of
* to expose it's GADT's nature and provide the folding function.
* Should run out of the box with: amm <the_file>
import $ivy.`org.typelevel:cats-core_2.12:1.6.0`
object demo {
import cats.{Applicative, Functor, Id, Semigroupal, Traverse}
View Lens_and_zipper_equivalence.scala
object LensToZiper {
This is a small sleight of hand to show how
are actually related to to zippers (getters + setters).
This connection give some insight about why lenses
have the properties they have. So let's define all
we need for lenses:
View ForceCovariance.scala
import scala.language.higherKinds
trait Functor[F[_]] {
def map[A,B](fa: F[A])(f: A => B): F[B]
/* Any functor is by definition covariant because:
Let A and B be two types such that A <: B, then
(fa: F[A]).map((a:A) => (a:S)) : F[S]
but also
View The_Batch_Monad.scala
This code was made to investigate if it is possible
to use a batch API as if it were a single item one.
More precisely, I have this batch API:
final case class Request(id: Int)
final case class Response(id: Int)
View One_concept_to_explain_them_all_and_in_the_theory_bind_them.scala
This piece of commented code aims to clarify some
misconceptions between several advanced concepts
in pure functional programming/category theory:
free monads, finally tagless approach, algebraic
These concepts are actually very close. They rely
on similar concepts and even represent the "same"
object (up to isomorphism!) from the theoretical
View GADTs_For_Implicits_Demo.scala
object Test {
/** Simple definition of Heterogeneous Lists
sealed abstract class HList {
def :::[H](head: H): H ::: this.type = Test.:::(head, this)
/** The empty list
chrilves / IsA.scala
Created Nov 23, 2018
A proof that the type `A` is of the form `F[elem]` for some type `elem`
View IsA.scala
/** A proof that the type {{{A}}} is of
* the form {{{F[elem]}}} for some type
* {{{elem}}}.
sealed abstract class IsA[F[_], A] {
type elem
def fold[G[_]](p: G[F[elem]]): G[A]
@inline implicit final def to: A =:= F[elem] = {
type G[X] = X =:= F[elem]
View General_Category.scala
import scala.collection.immutable.TreeSet
import scala.language.higherKinds
* A Category
trait Cat { cat =>
type obj[A]
type arr[A, B]
View DBMode_PathDependentTypes.scala
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]
You can’t perform that action at this time.