Skip to content

Instantly share code, notes, and snippets.

gneuvill / maybe.ts
Last active October 18, 2017 11:05
import {HKT as _} from "fp-ts/lib/HKT"
import {Equal, equal} from "./eq"
import {Functor, lift} from "fp-ts/lib/Functor"
import {Monad} from "fp-ts/lib/Monad"
import {Foldable} from "fp-ts/lib/Foldable"
import {constant} from "fp-ts/lib/function"
import {Traversable} from "fp-ts/lib/Traversable"
import {Applicative} from "fp-ts/lib/Applicative"
declare module "fp-ts/lib/HKT" {
import * as _Maybe from "./maybe"
import {maybe} from "./maybe"
import {Do} from "./syntax"
import Maybe = _Maybe.Maybe
type Person = {
name: string
age: number
import {Monad} from "fp-ts/lib/Monad"
import {HKT as _, HKTAs as __, HKTS} from "fp-ts/lib/HKT"
import {
Function1 as F,
public interface Leibniz<A, B> extends __2<Leibniz.µ, A, B> {
enum µ {}
<f> __<f, B> subst(__<f, A> p);
static <T> Leibniz<T, T> refl() { return HktId::id; }
default B coerce(A a) {
return _Leibniz.asId(subst((Id<A>) () -> a)).__();
gneuvill / cats-mtl.scala
Created May 23, 2017 18:26 — forked from aaronlevin/cats-mtl.scala
Does the cats-mtl design support for-comprehensions with multiple Monad constraints? Looks like it does!
package cats
import{StateT, WriterT}
import cats.implicits._
* TypeLevel is working on some alternative encodings of the Monad Transformer
* Library (MTL). The existing solution in cats was broken for a few reasons.
* One annoying issue made it imposisible to use for-comprehension with more
* than one Monad$FOO constraint owing to implicit resolution ambiguities.
gneuvill /
Last active May 18, 2016 23:08
Composable applications with reasonably priced monads : in java !
public abstract class Coproduct<f, g, A> implements __3<Coproduct.µ, f, g, A> {
private final Either<__<f, A>, __<g, A>> run;
protected Coproduct(Either<__<f, A>, __<g, A>> run) { = run;}
public final Either<__<f, A>, __<g, A>> run() { return run; }
public static <f, g, A> Coproduct<f, g, A> leftc(__<f, A> x) { return new Coproduct<f, g, A>(Left(x)) {}; }
public static <f, g, A> Coproduct<f, g, A> rightc(__<g, A> x) { return new Coproduct<f, g, A>(Right(x)) {}; }
gneuvill /
Last active October 24, 2016 19:59
@Data(flavour = Flavour.FJ)
public abstract class Free<f, A> implements __2<Free.µ, f, A> {
Free() {}
interface Cases<f, A, R> {
R Return(A a);
R Suspend(__<f, A> fa);
R Gosub(Sub<f, A, ?> sub);
abstract <R> R match(Cases<f, A, R> cases);
// given...
class Person {
final String name;
final Integer age;
final Date birth;
Person(String name, Integer age, Date birth) { = name;
this.age = age;
this.birth = birth;