Last active
March 26, 2018 06:30
-
-
Save dead-claudia/df15fe9908358c4441de55fee0f70dae to your computer and use it in GitHub Desktop.
Fantasy Land type defs based on https://github.com/Microsoft/TypeScript/pull/17961
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
// A complete set of type defs for Fantasy Land | |
type unknown = {} | null | undefined; | |
interface Setoid { | |
"fantasy-land/equals"(other: this): boolean; | |
} | |
interface Ord { | |
"fantasy-land/lte"(other: this): boolean; | |
} | |
interface Semigroupoid<T extends <A, B>(a: A, b: B) => Semigroupoid<T, A, B>, A, B> { | |
"fantasy-land/compose"<C>(this: T(A, B), other: T(B, C)): T(A, C); | |
} | |
interface Category<T extends <A>(a: A, b: B) => Category<T, A, B>, A, B> extends Semigroupoid<T, A, B> { | |
constructor: { | |
"fantasy-land/id"<A>(): T(A, A); | |
}; | |
} | |
interface Semigroup { | |
"fantasy-land/concat"(other: this): this; | |
} | |
type MonoidT<M extends Monoid> = {"fantasy-land/empty"(): M}; | |
interface Monoid extends Semigroup { | |
constructor: MonoidT<this>; | |
} | |
interface Group extends Monoid { | |
"fantasy-land/invert"(): this; | |
} | |
interface Filterable<T extends <A>(x: A) => Filterable<T, A>, A> { | |
"fantasy-land/filter"(this: T(A), func: (a: A) => boolean): T(A); | |
} | |
interface Functor<T extends <A>(x: A) => Functor<T, A>, A> { | |
"fantasy-land/map"<B>(this: T(A), f: (a: A) => B): T(B); | |
} | |
interface Contravariant<T extends <A>(x: A) => Contravariant<T, A>, A> { | |
"fantasy-land/contramap"<B>(this: T(A), f: (b: B) => A): T(B); | |
} | |
interface Apply<T extends <A>(x: A) => Apply<T, A>, A> extends Functor<T, A> { | |
"fantasy-land/ap"<B>(this: T(A), f: T((a: A) => B)): T(B); | |
} | |
interface Applicative<T extends <A>(x: A) => Applicative<T, A>, A> extends Apply<T, A> { | |
constructor: { | |
"fantasy-land/of"<A>(a: A): T(A); | |
}; | |
} | |
interface Alt<T extends <A>(x: A) => Alt<T, A>, A> extends Functor<T, A> { | |
"fantasy-land/alt"<A>(this: T(A), other: T(A)): T(A); | |
} | |
interface Plus<T extends <A>(x: A) => Plus<T, A>, A> extends Alt<T, A> { | |
constructor: { | |
"fantasy-land/zero"<A>(a: A): T(A); | |
}; | |
} | |
interface Alternative<T extends <A>(x: A) => Alternative<T, A>, A> extends Applicative<T, A>, Plus<T, A> {} | |
interface Foldable<T extends <A>(x: A) => Foldable<T, A>, A> { | |
"fantasy-land/reduce"<B>(this: T(A), func: (acc: B, a: A) => B, acc: B): B; | |
} | |
interface Traversable<T extends <A>(x: A) => Traversable<T, A>, A> extends Functor<T, A>, Foldable<T, A> { | |
"fantasy-land/traverse"<U extends <V>(x: V) => Applicative<U, V>, B>( | |
this: T(A), m: U(B | T(B))["constructor"], func: (a: A) => U(B), | |
): U(T(B)); | |
} | |
interface Chain<T extends <A>(x: A) => Chain<T, A>, A> extends Apply<T, A> { | |
"fantasy-land/chain"<B>(this: T(A), f: (a: A) => T(B)): T(B); | |
} | |
interface ChainRec<T extends <A>(x: A) => ChainRec<T, A>, A> extends Chain<T, A> { | |
constructor: { | |
"fantasy-land/chainRec"<A, B, C>( | |
func: (next: (a: A) => C, done: (b: B) => C, acc: A) => T(C), | |
acc: A, | |
): T(B); | |
}; | |
} | |
interface Monad<T extends <A>(x: A) => Chain<T, A>, A> extends Applicative<T, A>, Chain<T, A> {} | |
interface Extend<T extends <A>(x: A) => Extend<T, A>, A> { | |
"fantasy-land/extend"<B>(this: T(A), func: (a: T(A)) => B): T(B); | |
} | |
interface Comonad<T extends <A>(x: A) => Comonad<T, A>, A> extends Extend<T, A> { | |
"fantasy-land/extract"(this: T(A)): A; | |
} | |
interface Bifunctor<T extends <A, B>(a: A, b: B) => Bifunctor<T, A, B>, A, B> | |
extends Functor<<C extends B>(b: C) => T(A, C)> { | |
"fantasy-land/bimap"<C, D>(this: T(A, C), f: (a: A) => B, g: (c: C) => D): T(B, D); | |
} | |
interface Profunctor<T extends <A, B>(a: A, b: B) => Profunctor<T, A, B>, A, B> | |
extends Functor<<C extends B>(b: C) => T(A, C)> { | |
"fantasy-land/promap"<C, D>(this: T(B, C), f: (a: A) => B, g: (c: C) => D): T(A, D); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment