diff --git a/index.d.ts b/index.d.ts index dc7d9325..7d70743b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,137 +4,78 @@ export type Pair = [A, B]; export type Thunk = () => A; -export type Fn = (a: A) => B; -export type Fn2 = (a: A, b: B) => C; -export type Fn3 = (a: A, b: B, c: C) => D; -export type Fn4 = (a: A, b: B, c: C, d: D) => E; -export type Fn5 = (a: A, b: B, c: C, d: D, e: E) => F; +export type Fn = (a: A) => B; +export type Fn2 = (a: A) => (b: B) => C; +export type Fn3 = (a: A) => (b: B) => (c: C) => D; +export type Fn4 = (a: A) => (b: B) => (c: C) => (d: D) => E; +export type Fn5 = (a: A) => (b: B) => (c: C) => (d: D) => (e: E) => F; +export type Fn2_ = (a: A, b: B) => C; +export type Fn3_ = (a: A, b: B, c: C) => D; +export type Fn4_ = (a: A, b: B, c: C, d: D) => E; +export type Fn5_ = (a: A, b: B, c: C, d: D, e: E) => F; export type Predicate = (a: A) => boolean; export interface StrMap { [k: string]: A; } export interface Maybe { - 'fantasy-land/equals': (p: Maybe) => boolean; - 'fantasy-land/map': (p: (q: A) => B) => Maybe; - 'fantasy-land/ap': (p: Maybe<(q: A) => B>) => Maybe; - 'fantasy-land/chain': (p: (q: A) => Maybe) => Maybe; - 'fantasy-land/alt': (p: Maybe) => Maybe; - 'fantasy-land/reduce': (p: Fn2, s: B) => B; - 'fantasy-land/traverse': (p: TypeRep, q: (r: A) => Applicative) => Applicative>; -} - -export interface Either { - 'fantasy-land/equals': (p: Either) => boolean; - 'fantasy-land/map': (p: (q: B) => C) => Either; - 'fantasy-land/bimap': (p: Fn, q: Fn) => Either; - 'fantasy-land/ap': (p: Either C>) => Either; - 'fantasy-land/chain': (p: (q: B) => Either) => Either; - 'fantasy-land/alt': (p: Either) => Either; - 'fantasy-land/reduce': (p: Fn2, s: C) => C; - 'fantasy-land/traverse': (p: TypeRep, q: (r: B) => Applicative) => Applicative>; -} - - -type ValidNumber = number; -type FiniteNumber = number; -type NonZeroFiniteNumber = number; -type Integer = number; -type NonNegativeInteger = number; - - -interface TypeRep {} - - -interface Setoid { - 'fantasy-land/equals': (other: Setoid) => boolean; -} -interface Ord extends Setoid { - 'fantasy-land/lte': (other: Ord) => boolean; -} -interface Semigroupoid { - 'fantasy-land/compose': (other: Semigroupoid) => Semigroupoid; -} -interface Category extends Semigroupoid { constructor: { - 'fantasy-land/id': () => Category + '@@type': 'sanctuary/Maybe'; }; } -interface Semigroup { - 'fantasy-land/concat': (other: Semigroup) => Semigroup; -} -interface Monoid extends Semigroup { - constructor: { - 'fantasy-land/empty': () => Monoid - }; -} -interface Functor { - 'fantasy-land/map': (p: (q: A) => B) => Functor; -} -interface Bifunctor extends Functor { - 'fantasy-land/bimap': (p: Fn, q: Fn) => Bifunctor; -} -interface Profunctor extends Functor { - 'fantasy-land/promap': (p: Fn, q: Fn) => Profunctor; -} -interface Apply extends Functor { - 'fantasy-land/ap': (p: Apply<(q: A) => B>) => Apply; -} -interface ApplicativeTypeRep { - 'fantasy-land/of': (value: any) => any; -} -export interface Applicative extends Apply { -} -interface Chain extends Apply { - 'fantasy-land/chain': (p: (q: A) => Chain) => Chain; -} -interface ChainRec extends Chain { + +export interface Either { constructor: { - 'fantasy-land/chainRec': (p: (q: (r: A) => C, s: (t: B) => C, u: A) => ChainRec, v: A) => ChainRec + '@@type': 'sanctuary/Either'; }; } -interface Monad extends Applicative, Chain {} -interface Alt extends Functor { - 'fantasy-land/alt': (other: Alt) => Alt; -} -interface PlusTypeRep { - 'fantasy-land/zero': () => Plus; -} -interface Plus extends Alt { - constructor: PlusTypeRep; -} -interface Alternative extends Applicative, Plus { - constructor: ApplicativeTypeRep & PlusTypeRep; -} -interface Foldable { - 'fantasy-land/reduce': (p: Fn2, s: B) => B; -} -interface Traversable extends Functor, Foldable { - 'fantasy-land/traverse': (p: TypeRep, q: (r: A) => Applicative) => Applicative>; -} -interface Extend extends Functor { - 'fantasy-land/extend': (p: any) => any; -} -interface Comonad extends Extend { - 'fantasy-land/extract': () => A; -} -interface Contravariant { - 'fantasy-land/contramap': (p: (q: B) => A) => Contravariant; -} + + +type ValidNumber = number; +type FiniteNumber = number; +type NonZeroFiniteNumber = number; +type Integer = number; +type NonNegativeInteger = number; + + +export interface TypeRep {} + +export interface Setoid {} +export interface Ord extends Setoid {} +export interface Semigroupoid {} +export interface Category extends Semigroupoid {} +export interface Semigroup {} +export interface Monoid extends Semigroup {} +export interface Functor {} +export interface Bifunctor extends Functor {} +export interface Profunctor extends Functor {} +export interface Apply extends Functor {} +export interface Applicative extends Apply {} +export interface Chain extends Apply {} +export interface ChainRec extends Chain {} +export interface Monad extends Applicative, Chain {} +export interface Alt extends Functor {} +export interface Plus extends Alt {} +export interface Alternative extends Applicative, Plus {} +export interface Foldable {} +export interface Traversable extends Functor, Foldable {} +export interface Extend extends Functor {} +export interface Comonad extends Extend {} +export interface Contravariant {} export const Maybe: TypeRep; export const Nothing: Maybe; -export function Just(value: A): Maybe; +export function Just(x: A): Maybe; export const Either: TypeRep; -export function Left(value: A): Either; -export function Right(value: A): Either; +export function Left(x: A): Either; +export function Right(x: A): Either; // TODO: Specify return type -export function create(p: {checkTypes: boolean, env: any[]}): {}; +export function create(opts: {checkTypes: boolean, env: Array}): {}; -export const env: any[]; +export const env: Array; // Classify @@ -144,137 +85,39 @@ export function type(x: any): { version: NonNegativeInteger }; -export function is(p: TypeRep): Predicate; +export function is(typeRep: TypeRep): (x: any) => boolean; // Showable -export function toString(p: any): string; +export function toString(x: any): string; // Fantasy Land -export function equals(p: null): Predicate; -export function equals(p: undefined): Predicate; -export function equals(p: boolean): Predicate; -export function equals(p: number): Predicate; -export function equals(p: Date): Predicate; -export function equals(p: RegExp): Predicate; -export function equals(p: string): Predicate; -export function equals(p: Array): Predicate>; -export function equals(p: IArguments): Predicate; -export function equals(p: Error): Predicate; -// XXX: This is too general. Can we match "plain" objects only? -// export function equals(p: Object): Predicate; -export function equals(p: Function): Predicate; -export function equals(p: Setoid): Predicate>; - -export function lt(p: null): Predicate; -export function lt(p: undefined): Predicate; -export function lt(p: boolean): Predicate; -export function lt(p: number): Predicate; -export function lt(p: Date): Predicate; -export function lt(p: string): Predicate; -export function lt(p: Array): Predicate>; -export function lt(p: IArguments): Predicate; -export function lt(p: Ord): Predicate>; - -export function lt_(p: null): Predicate; -export function lt_(p: undefined): Predicate; -export function lt_(p: boolean): Predicate; -export function lt_(p: number): Predicate; -export function lt_(p: Date): Predicate; -export function lt_(p: string): Predicate; -export function lt_(p: Array): Predicate>; -export function lt_(p: IArguments): Predicate; -export function lt_(p: Ord): Predicate>; - -export function lte(p: null): Predicate; -export function lte(p: undefined): Predicate; -export function lte(p: boolean): Predicate; -export function lte(p: number): Predicate; -export function lte(p: Date): Predicate; -export function lte(p: string): Predicate; -export function lte(p: Array): Predicate>; -export function lte(p: IArguments): Predicate; -// XXX: This is too general. Can we match "plain" objects only? -// export function lte(p: Object): Predicate; -export function lte(p: Ord): Predicate>; - -export function lte_(p: null): Predicate; -export function lte_(p: undefined): Predicate; -export function lte_(p: boolean): Predicate; -export function lte_(p: number): Predicate; -export function lte_(p: Date): Predicate; -export function lte_(p: string): Predicate; -export function lte_(p: Array): Predicate>; -export function lte_(p: IArguments): Predicate; -export function lte_(p: Ord): Predicate>; - -export function gt(p: null): Predicate; -export function gt(p: undefined): Predicate; -export function gt(p: boolean): Predicate; -export function gt(p: number): Predicate; -export function gt(p: Date): Predicate; -export function gt(p: string): Predicate; -export function gt(p: Array): Predicate>; -export function gt(p: IArguments): Predicate; -export function gt(p: Ord): Predicate>; - -export function gt_(p: null): Predicate; -export function gt_(p: undefined): Predicate; -export function gt_(p: boolean): Predicate; -export function gt_(p: number): Predicate; -export function gt_(p: Date): Predicate; -export function gt_(p: string): Predicate; -export function gt_(p: Array): Predicate>; -export function gt_(p: IArguments): Predicate; -export function gt_(p: Ord): Predicate>; - -export function gte(p: null): Predicate; -export function gte(p: undefined): Predicate; -export function gte(p: boolean): Predicate; -export function gte(p: number): Predicate; -export function gte(p: Date): Predicate; -export function gte(p: string): Predicate; -export function gte(p: Array): Predicate>; -export function gte(p: IArguments): Predicate; -export function gte(p: Ord): Predicate>; - -export function gte_(p: null): Predicate; -export function gte_(p: undefined): Predicate; -export function gte_(p: boolean): Predicate; -export function gte_(p: number): Predicate; -export function gte_(p: Date): Predicate; -export function gte_(p: string): Predicate; -export function gte_(p: Array): Predicate>; -export function gte_(p: IArguments): Predicate; -export function gte_(p: Ord): Predicate>; - -export function min(p: Date): (q: Date) => Date; -export function min(p: number): (q: number) => number; -export function min(p: string): (q: string) => string; -export function min(p: Ord): (q: Ord) => Ord; - -export function max(p: Date): (q: Date) => Date; -export function max(p: number): (q: number) => number; -export function max(p: string): (q: string) => string; -export function max(p: Ord): (q: Ord) => Ord; +export function equals(x: Setoid): (y: Setoid) => boolean; + +export function lt (x: Ord): (y: Ord) => boolean; +export function lte(x: Ord): (y: Ord) => boolean; +export function gt (x: Ord): (y: Ord) => boolean; +export function gte(x: Ord): (y: Ord) => boolean; + +export function min(x: Ord): (y: Ord) => A; +export function max(x: Ord): (y: Ord) => A; export function id(p: TypeRep): Fn; export function id(p: TypeRep): Category; -export function concat(p: Array): (q: Array) => Array; -export function concat(p: Maybe): (q: Maybe) => Maybe; -export function concat(p: Semigroup): (q: Semigroup) => Semigroup; -export function concat (p: string): (q: string) => string; +export function concat(x: Semigroup): (y: Semigroup) => Semigroup; +export function concat(x: Array): (y: Array) => Array; +export function concat(x: StrMap): (y: StrMap) => StrMap; +export function concat (x: string): (y: string) => string; export function empty(p: TypeRep): Monoid; export function map(p: Fn): { - (q: Functor): Functor; - (q: Fn): Fn; - (q: StrMap): StrMap; - (q: Maybe): Maybe; - (q: Array): Array; + (q: Fn): Fn; + ( q: Array): Array; + ( q: StrMap): StrMap; + ( q: Functor): Functor; }; export function bimap(p: Fn): (q: Fn) => (r: Bifunctor) => Bifunctor; @@ -284,143 +127,102 @@ export function promap(p: Fn): (q: Fn) => { (r: Profunctor): Profunctor; }; -export function alt(p: Array): Fn, Array>; -export function alt(p: StrMap): Fn, StrMap>; -export function alt(p: Alt): Fn, Alt>; +export function alt(x: Alt): (y: Alt) => Alt; export function zero(p: TypeRep): Plus; -export function reduce(p: Fn>): (q: B) => (r: Array | StrMap | Maybe | Either | Foldable) => B; +export function reduce(p: Fn2): (q: B) => (r: Array | StrMap | Maybe | Either | Foldable) => B; -export function traverse(p: TypeRep): { - (q: Fn>): { - (r: Traversable): Array>; - (r: StrMap): Array< StrMap>; - (r: Array): Array< Array>; - }; - (q: Fn>): { - (r: Traversable): Maybe>; - (r: StrMap): Maybe< StrMap>; - (r: Array): Maybe< Array>; - }; - (q: Fn>): { - (r: Traversable): Applicative>; - (r: StrMap): Applicative< StrMap>; - (r: Array): Applicative< Array>; - }; -}; +export function traverse(typeRep: TypeRep): (f: Fn>) => (traversable: Traversable) => Applicative>; -export function sequence(p: TypeRep): { - (q: Traversable>): Applicative>; - (q: Traversable>): Array>; -}; +export function sequence(typeRep: TypeRep): (traversable: Traversable>) => Applicative>; -export function ap(p: Array>): (q: Array) => Array; -export function ap(p: StrMap>): (q: StrMap) => StrMap; -export function ap(p: Maybe>): (q: Maybe) => Maybe; export function ap(p: Apply>): (q: Apply) => Apply; -export function lift2(p: Fn>): { - (q: Fn): Fn< Fn, Fn>; - (q: Array): Fn< Array, Array>; - (q: Maybe): Fn< Maybe, Maybe>; - (q: Either): Fn, Either>; - (q: Apply): Fn< Apply, Apply>; +export function lift2(f: Fn2): { + (x: Fn): (y: Fn) => Fn; + ( x: Apply): (y: Apply) => Apply; }; -export function lift3(p: Fn>>): { - (q: Fn): Fn< Fn, Fn< Fn, Fn>>; - (q: Array): Fn< Array, Fn< Array, Array>>; - (q: Maybe): Fn< Maybe, Fn< Maybe, Maybe>>; - (q: Either): Fn, Fn, Either>>; - (q: Apply): Fn< Apply, Fn< Apply, Apply>>; +export function lift3(f: Fn3): { + (x: Fn): (y: Fn) => (z: Fn) => Fn; + ( x: Apply): (y: Apply) => (z: Apply) => Apply; }; -export function apFirst(p: Array): (q: Array) => Array; -export function apFirst(p: Apply): (q: Apply) => Apply; +export function apFirst (x: Apply): (y: Apply) => Apply; +export function apSecond(x: Apply): (y: Apply) => Apply; -export function apSecond(p: Array): (q: Array) => Array; -export function apSecond(p: Apply): (q: Apply) => Apply; +export function of(typeRep: TypeRep): (x: A) => Fn; +export function of(typeRep: TypeRep): (x: A) => Applicative; -export function of(p: TypeRep): (q: A) => Fn; -export function of(p: TypeRep): (q: A) => Applicative; +export function chain(f: Fn2 ): (chain_: Fn) => Fn; +export function chain (f: Fn >): (chain_: Chain) => Chain; -export function chain(p: Fn>): Fn, Fn>; -export function chain (p: Fn>): Fn, Array>; -export function chain (p: Fn>): Fn, Chain>; +export function join(chain_: Fn2 ): Fn; +export function join (chain_: Array>): Array; +export function join (chain_: Maybe>): Maybe; +export function join (chain_: Chain>): Chain; -export function join(p: Fn>): Fn; -export function join (p: Array>): Array; -export function join (p: Maybe>): Maybe; -export function join (p: Chain>): Chain; - -export function chainRec(p: TypeRep): { - (q: Fn>>): Fn>; - (q: Fn>>): Fn>; - (q: Fn>>): Fn>; - (q: Fn>>): Fn>; +export function chainRec(typeRep: TypeRep): { + (f: Fn2> ): (x: A) => Fn; + (f: Fn >>): (x: A) => ChainRec; }; -export function extend(p: Fn, B>): Fn, Array>; -export function extend(p: Fn, B>): Fn, Extend>; - -export function extract(p: Comonad): A; +export function extend(f: Fn, B>): (extend_: Extend) => Extend; -export function contramap(p: Fn): { - ( q: Contravariant): Contravariant; - (q: Fn): Fn; -}; +export function extract(comonad: Comonad): A; -export function filter(p: Predicate): { - (q: Array): Array; - (q: Foldable): Foldable; +export function contramap(f: Fn): { + (contravariant: Fn): Fn; + ( contravariant: Contravariant): Contravariant; }; -export function filterM(p: Predicate): { - (q: Maybe): Maybe; - (q: Array): Array; - (q: Foldable): Foldable; +export function filter (pred: Predicate): { + (m: Array): Array; + (m: Foldable): Foldable; }; -export function takeWhile(p: Predicate): { - (q: Maybe): Maybe; - (q: Array): Array; - (q: Foldable): Foldable; +export function filterM(pred: Predicate): { + (m: Array): Array; + (m: Foldable): Foldable; }; -export function dropWhile(p: Predicate): { - (q: Maybe): Maybe; - (q: Array): Array; - (q: Foldable): Foldable; -}; +export function takeWhile(pred: Predicate): (foldable: Foldable) => Foldable; +export function dropWhile(pred: Predicate): (foldable: Foldable) => Foldable; // Combinator -export function I(p: A): A; +export function I(x: A): A; -export function K(p: A): Fn; +export function K(x: A): (y: B) => A; -export function T(p: A): Fn, B>; +export function T(x: A): (f: Fn) => B; // Function -export function curry2(p: Fn2): Fn>; +export function curry2(f: Fn2_): Fn2; -export function curry3(p: Fn3): Fn>>; +export function curry3(f: Fn3_): Fn3; -export function curry4(p: Fn4): Fn>>>; +export function curry4(f: Fn4_): Fn4; -export function curry5(p: Fn5): Fn>>>>; +export function curry5(f: Fn5_): Fn5; -export function flip(p: Fn>): Fn>; +export function flip(f: Fn2): Fn2; // Composition -export function compose(p: Fn): (q: Fn) => Fn; +export function compose(f: Fn): (g: Fn) => Fn; +export function compose(x: Semigroupoid): (y: Semigroupoid) => Semigroupoid; -export function pipe(p: Array>): Fn; +export function pipe (fs: [Fn]): (x: A) => B; +export function pipe (fs: [Fn, Fn]): (x: A) => C; +export function pipe (fs: [Fn, Fn, Fn]): (x: A) => D; +export function pipe (fs: [Fn, Fn, Fn, Fn]): (x: A) => E; +export function pipe(fs: [Fn, Fn, Fn, Fn, Fn]): (x: A) => F; +export function pipe (fs: Array>): (x: A) => B; -export function on(p: Fn>): Fn, Fn>>; +export function on(p: Fn2): (q: Fn) => (r: A) => Fn; // TODO: Maybe @@ -428,27 +230,27 @@ export function isNothing(p: Maybe): boolean; export function isJust(p: Maybe): boolean; -export function fromMaybe(p: A): Fn, A>; +export function fromMaybe(p: A): (q: Maybe) => A; -export function fromMaybe_(p: Thunk): Fn, A>; +export function fromMaybe_(p: Thunk): (q: Maybe) => A; export function maybeToNullable(p: Maybe): Nullable; export function toMaybe(p: A | null | undefined): Maybe; -export function maybe(p: B): (q: Fn) => Fn, B>; +export function maybe(p: B): (q: Fn) => (r: Maybe) => B; -export function maybe_(p: Thunk): (q: Fn) => Fn, B>; +export function maybe_(p: Thunk): (q: Fn) => (r: Maybe) => B; export function justs(p: Array>): Array; -export function mapMaybe(p: Fn>): Fn, Array>; +export function mapMaybe(p: Fn>): (q: Array) => Array; export function encase(p: Fn): Fn>; -export function encase2(p: Fn>): Fn>>; +export function encase2(p: Fn2): Fn2>; -export function encase3(p: Fn>>): Fn>>>; +export function encase3(p: Fn3): Fn3>; export function maybeToEither(p: A): (q: Maybe) => Either; @@ -462,37 +264,37 @@ export function fromEither(p: B): (q: Either) => B; export function toEither(p: A): (q: B | null | undefined) => Either; -export function either(p: Fn): (q: Fn) => Fn, C>; +export function either(p: Fn): (q: Fn) => (r: Either) => C; export function lefts(p: Array>): Array; export function rights(p: Array>): Array; -export function tagBy(p: Predicate): Fn>; +export function tagBy(p: Predicate): (q: A) => Either; export function encaseEither(p: Fn): (q: Fn) => Fn>; -export function encaseEither2(p: Fn): (q: Fn>) => Fn>>; +export function encaseEither2(p: Fn): (q: Fn2) => Fn2>; -export function encaseEither3(p: Fn): (q: Fn>>) => Fn>>>; +export function encaseEither3(p: Fn): (q: Fn3) => Fn3>; export function eitherToMaybe(p: Either): Maybe; // Logic -export function and(p: boolean): Predicate; +export function and(p: boolean): (q: boolean) => boolean; -export function or(p: boolean): Predicate; +export function or(p: boolean): (q: boolean) => boolean; export function not(p: boolean): boolean; export function complement(p: Predicate): Predicate; -export function ifElse(p: Predicate): Fn, Fn, Fn>>; +export function ifElse(p: Predicate): (q: Fn) => (r: Fn) => Fn; -export function when(p: Predicate): Fn, Fn>; +export function when(p: Predicate): (q: Fn) => Fn; -export function unless(p: Predicate): Fn, Fn>; +export function unless(p: Predicate): (q: Fn) => Fn; export function allPass(p: Array>): Predicate; @@ -501,23 +303,16 @@ export function anyPass(p: Array>): Predicate; // List export interface ListToMaybeList { - (xs: string): Maybe; + (xs: string): Maybe; (xs: Array): Maybe>; } -export interface ListToMaybeElement { - (xs: string): Maybe; - (xs: Array): Maybe; -} - -export interface ListToMaybeIndex { - (xs: string): Maybe; - (xs: Array): Maybe; -} - -export function slice(beg: Integer): Fn; +export function slice(p: Integer): (q: Integer) => ListToMaybeList; -export function at(n: Integer): ListToMaybeElement; +export function at(p: Integer): { + (q: string): Maybe; + (q: Array): Maybe; +}; export function head(xs: string): Maybe; export function head(xs: Array): Maybe; @@ -542,44 +337,40 @@ export function dropLast(n: Integer): ListToMaybeList; // Array // TODO: Fantasyland overloads, non-curried versions -export function append(p: A): { - (q: Applicative): Applicative; - (q: Maybe): Maybe; - (q: Either): Either; - (q: Array): Array; +export function append(x: A): { + (xs: Array): Array; + (xs: Applicative): Applicative; }; -export function prepend(p: A): { - (q: Applicative): Applicative; - (q: Maybe): Maybe; - (q: Either): Either; - (q: Array): Array; +export function prepend(x: A): { + (xs: Array): Array; + (xs: Applicative): Applicative; }; -export function joinWith(sep: string): Fn, string>; +export function joinWith(p: string): (q: Array) => string; -export function elem(p: A): (q: Array | StrMap | Foldable) => boolean; +export function elem(p: A): (q: Foldable | StrMap | Array) => boolean; export function find(p: Predicate): (q: Array | StrMap | Foldable) => Maybe; -export function pluck(p: string): { - (q: Array): Array; - (q: Maybe): Maybe; - (q: Functor): Functor; -}; +export function pluck(key: string): (xs: Functor) => Functor; -export function unfoldr(p: Fn>>): Fn>; +export function unfoldr(f: Fn>>): (x: B) => Array; -export function range(start: Integer): Fn>; +export function range(from: Integer): (to: Integer) => Array; -export function groupBy(p: Fn>): Fn, Array>>; +export function groupBy(f: Fn2): (xs: Array) => Array>; -export function reverse(xs: string): string; -export function reverse(xs: Array): Array; +export function reverse(foldable: Array): Array; +export function reverse(foldable: Foldable): Foldable; -export function sort(xs: Array): Array; +export function sort(foldable: Array): Array; +export function sort(foldable: Foldable): Foldable; -export function sortBy(p: Fn): Fn, Array>; +export function sortBy(f: Fn>): { + (foldable: Array): Array; + (foldable: Foldable): Foldable; +}; // Object @@ -587,9 +378,9 @@ export function prop(p: string): (q: A) => B; export function props(p: Array): (q: A) => B; -export function get(p: Predicate): Fn>>; +export function get(p: Predicate): (q: string) => (r: any) => Maybe; -export function gets(p: Predicate): Fn, Fn>>; +export function gets(p: Predicate): (q: Array) => (r: any) => Maybe; // StrMap @@ -603,27 +394,21 @@ export function pairs(p: StrMap): Array>; export function negate(n: ValidNumber): ValidNumber; -export function add(x: FiniteNumber): Fn; +export function add(p: FiniteNumber): (q: FiniteNumber) => FiniteNumber; export function sum(p: Foldable): FiniteNumber; export function sum(p: Array): FiniteNumber; -export function sub(x: FiniteNumber): Fn; +export function sub(p: FiniteNumber): (q: FiniteNumber) => FiniteNumber; -export function sub_(x: FiniteNumber): Fn; - -export function mult(x: FiniteNumber): Fn; +export function mult(x: FiniteNumber): (q: FiniteNumber) => FiniteNumber; export function product(p: Foldable): FiniteNumber; export function product(p: Array): FiniteNumber; -export function div(p: NonZeroFiniteNumber): Fn; - -export function div_(p: FiniteNumber): Fn; - -export function pow(p: FiniteNumber): Fn; +export function div(p: NonZeroFiniteNumber): (q: FiniteNumber) => FiniteNumber; -export function pow_(p: FiniteNumber): Fn; +export function pow(p: FiniteNumber): (q: FiniteNumber) => FiniteNumber; export function mean(p: Foldable): Maybe; export function mean(p: Array): Maybe; @@ -640,13 +425,13 @@ export function parseDate(s: string): Maybe; export function parseFloat(s: string): Maybe; -export function parseInt(radix: Integer): Fn>; +export function parseInt(p: Integer): (q: string) => Maybe; -export function parseJson(pred: Predicate): Fn>; +export function parseJson(p: Predicate): (q: string) => Maybe; // RegExp -export function regex(flags: string): Fn; +export function regex(p: string): (q: string) => RegExp; export function regexEscape(s: string): string; @@ -657,9 +442,9 @@ interface MatchObj { groups: Array>; } -export function match(pattern: RegExp): Fn>>; +export function match(pattern: RegExp): (q: string) => Array>; -export function matchAll(pattern: RegExp): Fn>; +export function matchAll(pattern: RegExp): (q: string) => Array; // String @@ -669,9 +454,9 @@ export function toLower(s: string): string; export function trim(s: string): string; -export function stripPrefix(prefix: string): Fn>; +export function stripPrefix(prefix: string): (q: string) => Maybe; -export function stripSuffix(suffix: string): Fn>; +export function stripSuffix(suffix: string): (q: string) => Maybe; export function words(s: string): Array; @@ -681,6 +466,6 @@ export function lines(s: string): Array; export function unlines(xs: Array): string; -export function splitOn(separator: string): Fn>; +export function splitOn(separator: string): (q: string) => Array; -export function splitOnRegex(pattern: RegExp): Fn>; +export function splitOnRegex(pattern: RegExp): (q: string) => Array; diff --git a/test-ts/alt.ts b/test-ts/alt.ts index 306f31e7..e64a1d1d 100644 --- a/test-ts/alt.ts +++ b/test-ts/alt.ts @@ -10,8 +10,7 @@ test('alt', () => { eq(S.alt.toString(), 'alt :: Alt f => f a -> f a -> f a'); eq(S.alt([])([]), []); - const empty: number[] = []; // Microsoft/TypeScript#8944 - eq(S.alt(empty)([1, 2, 3]), [1, 2, 3]); + eq(S.alt([])([1, 2, 3]), [1, 2, 3]); eq(S.alt([1, 2, 3])([]), [1, 2, 3]); eq(S.alt([1, 2, 3])([4, 5, 6]), [1, 2, 3, 4, 5, 6]); eq(S.alt({})({}), {}); diff --git a/test-ts/chain.ts b/test-ts/chain.ts index d1b1a605..20558de3 100644 --- a/test-ts/chain.ts +++ b/test-ts/chain.ts @@ -9,7 +9,7 @@ test('chain', () => { eq(S.chain.length, 2); eq(S.chain.toString(), 'chain :: Chain m => (a -> m b) -> m a -> m b'); - eq(S.chain(S.I)([[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]); + eq(S.chain(S.I)([[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]); eq(S.chain(S.parseFloat)(S.Nothing), S.Nothing); eq(S.chain(S.parseFloat)(S.Just('X')), S.Nothing); eq(S.chain(S.parseFloat)(S.Just('0')), S.Just(0)); diff --git a/test-ts/concat.ts b/test-ts/concat.ts index f74665ec..b34dc3ed 100644 --- a/test-ts/concat.ts +++ b/test-ts/concat.ts @@ -11,7 +11,7 @@ test('concat', () => { eq(S.concat([])([]), []); eq(S.concat([1, 2, 3])([]), [1, 2, 3]); - eq(S.concat([])([4, 5, 6]), [4, 5, 6]); + eq(S.concat([])([4, 5, 6]), [4, 5, 6]); eq(S.concat([1, 2, 3])([4, 5, 6]), [1, 2, 3, 4, 5, 6]); eq(S.concat('')(''), ''); @@ -19,7 +19,7 @@ test('concat', () => { eq(S.concat('')('bar'), 'bar'); eq(S.concat('foo')('bar'), 'foobar'); - eq(S.concat>(S.Nothing)(S.Nothing), S.Nothing); + eq(S.concat(S.Nothing)(S.Nothing), S.Nothing); eq(S.concat(S.Just('foo'))(S.Nothing), S.Just('foo')); eq(S.concat(S.Nothing)(S.Just('bar')), S.Just('bar')); eq(S.concat(S.Just('foo'))(S.Just('bar')), S.Just('foobar')); diff --git a/test-ts/groupBy.ts b/test-ts/groupBy.ts index 0dafb5b7..a95b3ef8 100644 --- a/test-ts/groupBy.ts +++ b/test-ts/groupBy.ts @@ -25,10 +25,10 @@ test('groupBy', () => { eq(S.groupBy(productsOf3)([]), []); eq(S.groupBy(productsOf3)([1, 2, 3, 4, 5, 6, 7, 8, 9]), [[1], [2, 3], [4], [5, 6], [7], [8, 9]]); - eq(S.groupBy(S.equals)([1, 1, 2, 1, 1]), [[1, 1], [2], [1, 1]]); + eq(S.groupBy(S.equals)([1, 1, 2, 1, 1]), [[1, 1], [2], [1, 1]]); eq(S.groupBy(zeroSum)([2, -3, 3, 3, 3, 4, -4, 4]), [[2], [-3, 3, 3, 3], [4, -4], [4]]); - jsc.assert(jsc.forall('nat -> nat -> bool', 'array nat', function(f: (x: number) => (y: number) => boolean, xs: number[]) { + jsc.assert(jsc.forall('nat -> nat -> bool', 'array nat', function(f: (x: number) => (y: number) => boolean, xs: Array) { return S.equals(S.join(S.groupBy(f)(xs)))(xs); }), {tests: 100}); diff --git a/test-ts/on.ts b/test-ts/on.ts index 0d570b04..61df019c 100644 --- a/test-ts/on.ts +++ b/test-ts/on.ts @@ -11,6 +11,6 @@ test('on', () => { eq(S.on.toString(), 'on :: (b -> b -> c) -> (a -> b) -> a -> a -> c'); eq(S.on(rem)(S.prop('x'))({x: 5, y: 5})({x: 3, y: 3}), 2); - eq(S.on(S.concat)(S.reverse)([1, 2, 3])([4, 5, 6]), [3, 2, 1, 6, 5, 4]); + eq(S.on, Array, Array>(S.concat)(S.reverse)([1, 2, 3])([4, 5, 6]), [3, 2, 1, 6, 5, 4]); }); diff --git a/test-ts/reduce.ts b/test-ts/reduce.ts index c5076f55..59f15352 100644 --- a/test-ts/reduce.ts +++ b/test-ts/reduce.ts @@ -15,6 +15,6 @@ test('reduce', () => { eq(S.reduce(S.concat)('x')({a: 'A', b: 'B', c: 'C'}), 'xABC'); eq(S.reduce(S.concat)('x')({c: 'C', b: 'B', a: 'A'}), 'xABC'); eq(S.reduce(S.concat)('x')(S.Just('A')), 'xA'); - eq(S.reduce(S.lift2(S.concat))(S.Just('x'))([S.Just('A'), S.Just('B'), S.Just('C')]), S.Just('xABC')); + eq(S.reduce(S.lift2(S.concat))(S.Just('x'))([S.Just('A'), S.Just('B'), S.Just('C')]), S.Just('xABC')); }); diff --git a/test-ts/traverse.ts b/test-ts/traverse.ts index 16b30dad..e45dc8c4 100644 --- a/test-ts/traverse.ts +++ b/test-ts/traverse.ts @@ -1,4 +1,4 @@ -import * as S from '..'; +const S = require('../test/internal/sanctuary'); import Identity from './internal/Identity'; import eq from './internal/eq'; @@ -17,19 +17,19 @@ test('traverse', () => { eq(S.traverse(S.Maybe)(S.parseInt(16))({a: 'A', b: 'B', c: 'C'}), S.Just({a: 10, b: 11, c: 12})); eq(S.traverse(S.Maybe)(S.parseInt(16))({a: 'A', b: 'B', c: 'C', x: 'X'}), S.Nothing); - eq(S.traverse(Array), string>(S.I)([]), [[]]); - eq(S.traverse(Array), string>(S.I)([['A', 'a']]), [['A'], ['a']]); - eq(S.traverse(Array), string>(S.I)([['A', 'a'], ['B']]), [['A', 'B'], ['a', 'B']]); - eq(S.traverse(Array), string>(S.I)([['A', 'a'], ['B', 'b']]), [['A', 'B'], ['A', 'b'], ['a', 'B'], ['a', 'b']]); + eq(S.traverse(Array)(S.I)([]), [[]]); + eq(S.traverse(Array)(S.I)([['A', 'a']]), [['A'], ['a']]); + eq(S.traverse(Array)(S.I)([['A', 'a'], ['B']]), [['A', 'B'], ['a', 'B']]); + eq(S.traverse(Array)(S.I)([['A', 'a'], ['B', 'b']]), [['A', 'B'], ['A', 'b'], ['a', 'B'], ['a', 'b']]); eq(S.traverse(Array)(S.words)(of('')), []); eq(S.traverse(Array)(S.words)(of('foo')), [of('foo')]); eq(S.traverse(Array)(S.words)(of('foo bar')), [of('foo'), of('bar')]); eq(S.traverse(Array)(S.words)(of('foo bar baz')), [of('foo'), of('bar'), of('baz')]); - eq(S.traverse(Identity), number>(S.I)([]), of([])); - eq(S.traverse(Identity), number>(S.I)([of(1)]), of([1])); - eq(S.traverse(Identity), number>(S.I)([of(1), of(2)]), of([1, 2])); - eq(S.traverse(Identity), number>(S.I)([of(1), of(2), of(3)]), of([1, 2, 3])); + eq(S.traverse(Identity)(S.I)([]), of([])); + eq(S.traverse(Identity)(S.I)([of(1)]), of([1])); + eq(S.traverse(Identity)(S.I)([of(1), of(2)]), of([1, 2])); + eq(S.traverse(Identity)(S.I)([of(1), of(2), of(3)]), of([1, 2, 3])); }); diff --git a/test/typescript/append.ts b/test/typescript/append.ts index 39a1f6ba..f75885af 100644 --- a/test/typescript/append.ts +++ b/test/typescript/append.ts @@ -3,5 +3,5 @@ import {append} from '../..'; // $ExpectType number[] append(3)([1, 2]); -// $ExpectError Argument of type 'number[]' is not assignable to parameter of type 'string[]'. +// $ExpectType Applicative append('foo')([1, 2]); diff --git a/test/typescript/elem.ts b/test/typescript/elem.ts index ad579034..a5c8d4ef 100644 --- a/test/typescript/elem.ts +++ b/test/typescript/elem.ts @@ -6,8 +6,8 @@ elem('foo')(['foo', 'bar']); // $ExpectType boolean elem('foo')({a: 'foo', b: 'bar'}); -// $ExpectError Argument of type 'string[]' is not assignable to parameter of type 'number[] | Foldable | StrMap'. +// $ExpectType boolean elem(1)(['foo', 'bar']); -// $ExpectError Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'number[] | Foldable | StrMap'. +// $ExpectType boolean elem(1)({a: 'foo', b: 'bar'}); diff --git a/test/typescript/filterM.ts b/test/typescript/filterM.ts index 799f8551..5b88397a 100644 --- a/test/typescript/filterM.ts +++ b/test/typescript/filterM.ts @@ -9,8 +9,8 @@ filterM(odd)([1, 2, 3]); // $ExpectError Argument of type '(n: number) => 0' is not assignable to parameter of type 'Predicate'. filterM((n: number) => 0)([1, 2, 3]); -// $ExpectType Maybe +// $ExpectType Foldable filterM(odd)(Nothing); -// $ExpectType Maybe +// $ExpectType Foldable filterM(odd)(Just(1)); diff --git a/test/typescript/find.ts b/test/typescript/find.ts index 91925937..739f0b59 100644 --- a/test/typescript/find.ts +++ b/test/typescript/find.ts @@ -3,5 +3,5 @@ import {find, odd} from '../..'; // $ExpectType Maybe find(odd)([1, 2, 3]); -// $ExpectError Argument of type 'string[]' is not assignable to parameter of type 'number[] | Foldable | StrMap'. +// $ExpectType Maybe find(odd)(['foo', 'bar']); diff --git a/test/typescript/map.ts b/test/typescript/map.ts index 781ada44..e5950a77 100644 --- a/test/typescript/map.ts +++ b/test/typescript/map.ts @@ -12,7 +12,7 @@ map(mult(2))([1, 2, 3]); // $ExpectError The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. map(n => n * 2)(['foo', 1, 2]); -// $ExpectError Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +// $ExpectType Functor map(mult(2))(['foo', 1, 2]); // TODO: Add tests using Maybe, Either, Functor, placeholder params diff --git a/test/typescript/pipe.ts b/test/typescript/pipe.ts index f6525fc4..0f601344 100644 --- a/test/typescript/pipe.ts +++ b/test/typescript/pipe.ts @@ -1,7 +1,28 @@ -import {add, sub, pipe} from '../..'; +import {add, pipe} from '../..'; -// $ExpectType any -pipe([add(1), sub(1)])(10); +// $ExpectType {} +pipe([])(0); -// $ExpectType any -pipe([add(1), sub(1)])('x'); +// $ExpectType number +pipe([add(1)])(0); + +// $ExpectType number +pipe([add(1), add(1)])(0); + +// $ExpectType number +pipe([add(1), add(1), add(1)])(0); + +// $ExpectType number +pipe([add(1), add(1), add(1), add(1)])(0); + +// $ExpectType number +pipe([add(1), add(1), add(1), add(1), add(1)])(0); + +// $ExpectType number +pipe([add(1), add(1), add(1), add(1), add(1), add(1)])(0); + +// $ExpectType number +pipe([add(1), add(1), add(1), add(1), add(1), add(1), add(1)])(0); + +// $ExpectType string +pipe([(s: string) => s.length, add(1), add(1), (n: number) => n.toFixed(2)])(''); diff --git a/test/typescript/pluck.ts b/test/typescript/pluck.ts index 0d1d134a..cbceefd2 100644 --- a/test/typescript/pluck.ts +++ b/test/typescript/pluck.ts @@ -1,7 +1,7 @@ import {pluck} from '../..'; -// $ExpectType any[] +// $ExpectType Functor pluck('x')([{x: 1}, {x: 2, y: 3}]); -// $ExpectType any[] +// $ExpectType Functor pluck('x')([{x: 'foo'}, {x: 'bar', y: 'baz'}]); diff --git a/test/typescript/prepend.ts b/test/typescript/prepend.ts index cf1980de..59c78ee0 100644 --- a/test/typescript/prepend.ts +++ b/test/typescript/prepend.ts @@ -3,5 +3,5 @@ import {prepend} from '../..'; // $ExpectType number[] prepend(3)([1, 2]); -// $ExpectError Argument of type 'number[]' is not assignable to parameter of type 'string[]'. +// $ExpectType Applicative prepend('foo')([1, 2]); diff --git a/test/typescript/reduce.ts b/test/typescript/reduce.ts index 0f6406b3..16f24c62 100644 --- a/test/typescript/reduce.ts +++ b/test/typescript/reduce.ts @@ -1,4 +1,4 @@ -import {Just, Nothing, add, concat, reduce} from '../..'; +import {Just, Nothing, add, reduce} from '../..'; // $ExpectType number reduce(add)(0)([1, 2, 3]); @@ -7,9 +7,9 @@ reduce(add)(0)([1, 2, 3]); reduce((s1: string) => s2 => s1 + s2)('a')(['b', 'c']); // $ExpectType string[] -reduce((a1: string[]) => a2 => concat(a1)(a2))([])([['a'], [], ['b', 'c']]); +reduce((a1: Array) => a2 => a1.concat(a2))([])([['a'], [], ['b', 'c']]); -// $ExpectError Argument of type '(string | number)[]' is not assignable to parameter of type 'number[] | Maybe | Foldable | StrMap | Either<{}, number>'. +// $ExpectType number reduce(add)(0)([1, 'foo', 3]); // TODO: Placeholder tests, foldable tests, curried version tests, type error tests diff --git a/test/typescript/reverse.ts b/test/typescript/reverse.ts index 3f12230d..fbdb7e3e 100644 --- a/test/typescript/reverse.ts +++ b/test/typescript/reverse.ts @@ -1,8 +1,5 @@ import {reverse} from '../..'; -// $ExpectType string -reverse('foo'); - // $ExpectType number[] reverse([1, 2, 3]); diff --git a/tslint.json b/tslint.json index bfab462a..e5b0048b 100644 --- a/tslint.json +++ b/tslint.json @@ -8,6 +8,7 @@ "space-before-function-paren": false, "typedef-whitespace": false, "unified-signatures": false, + "variable-name": false, "whitespace": false } }