forked from ramda/types
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into groupby-partial
* origin/develop: Update: Overload reordering (ramda#48) Update: count (ramda#40) Update: `of` now binary function (ramda#41) New: swap (ramda#42)
- Loading branch information
Showing
168 changed files
with
547 additions
and
362 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expectType, expectError, expectAssignable } from 'tsd'; | ||
import { count, isNotNil } from '../es'; | ||
|
||
expectType<number>(count(x => x < 5, [1, 2, 3, 4, 5])); | ||
|
||
// expectError when types don't match | ||
expectError(count((x: number) => x < 5, ['a', 'b', 'c'])); | ||
expectError(count((x: string) => x === 'ok', [1, 2, 3, 4, 5])); | ||
|
||
// expectType doesn't work here because the `T` defined in the generic is not the same `T` returned by `count(isNotNil)` | ||
expectAssignable<<T>(list: readonly T[]) => number>(count(isNotNil)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { expectType } from 'tsd'; | ||
|
||
import { __, of } from '../es'; | ||
|
||
// Array special handler | ||
expectType<<T>(value: T) => T[]>(of(Array)); | ||
|
||
// of(ctor)(val) | ||
expectType<string[]>(of(Array)('a')); | ||
expectType<number[]>(of(Array)(1)); | ||
// of(__, val)(ctor) | ||
expectType<string[]>(of(__, 'a')(Array)); | ||
expectType<number[]>(of(__, 1)(Array)); | ||
// of(ctor, val) | ||
expectType<string[]>(of(Array, 'a')); | ||
expectType<number[]>(of(Array, 1)); | ||
|
||
abstract class Maybe<A> { | ||
static of: <T>(val: T) => Maybe<T> = <T>(val: T) => new Just<T>(val); | ||
|
||
public value: A; | ||
|
||
constructor(value: A) { | ||
this.value = value; | ||
} | ||
|
||
abstract map<B>(fn: (value: A) => B): Maybe<B>; | ||
} | ||
|
||
class Just<A> extends Maybe<A> { | ||
constructor(value: A) { | ||
super(value); | ||
} | ||
|
||
map<B>(fn: (value: A) => B): Maybe<B> { | ||
return new Just(fn(this.value)); | ||
} | ||
} | ||
|
||
// Applicatives | ||
// `Maybe<unknown>` because no higher kinded types in typescript, cast it to be more specific | ||
|
||
expectType<Maybe<unknown>>(of(Maybe)(1)); | ||
expectType<Maybe<number>>(of(Maybe)(1) as Maybe<number>); | ||
|
||
expectType<Maybe<unknown>>(of(__, 1)(Maybe)); | ||
expectType<Maybe<number>>(of(__, 1)(Maybe) as Maybe<number>); | ||
|
||
expectType<Maybe<unknown>>(of(Maybe, 1)); | ||
expectType<Maybe<number>>(of(Maybe, 1) as Maybe<number>); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expectType } from 'tsd'; | ||
import { __, pipe, compose, swap } from '../es'; | ||
|
||
const indexA = 0; | ||
const indexB = 1; | ||
const list: number[] = []; | ||
|
||
expectType<number[]>(swap(indexA, indexB, list)); | ||
|
||
expectType<number[]>(swap(__, indexB, list)(indexA)); | ||
|
||
expectType<number[]>(swap(indexA, __, list)(indexB)); | ||
|
||
expectType<number[]>(swap(__, __, list)(indexA, indexB)); | ||
expectType<number[]>(swap(__, __, list)(__, indexB)(indexA)); | ||
expectType<number[]>(swap(__, __, list)(indexA)(indexB)); | ||
|
||
expectType<number[]>(swap(indexA, indexB)(list)); | ||
|
||
expectType<number[]>(swap(__, indexB)(indexA, list)); | ||
expectType<number[]>(swap(__, indexB)(__, list)(indexA)); | ||
expectType<number[]>(swap(__, indexB)(indexA)(list)); | ||
|
||
expectType<number[]>(swap(indexA)(indexB, list)); | ||
expectType<number[]>(swap(indexA)(__, list)(indexB)); | ||
expectType<number[]>(swap(indexA)(indexB)(list)); | ||
|
||
// sanity checks for compose and pipe | ||
expectType<(list: readonly number[]) => number[]>(pipe(swap(indexA, indexB))); | ||
expectType<(list: readonly number[]) => number[]>(compose(swap(indexA, indexB))); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// no need to type for __: Placeholder, because you'll never need to with addition | ||
export function add(a: number, b: number): number; | ||
export function add(a: number): (b: number) => number; | ||
export function add(a: number, b: number): number; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { InferAllAType, Placeholder } from './util/tools'; | ||
|
||
// all(fn, list) | ||
export function all<T>(fn: (a: T) => boolean, list: readonly T[]): boolean; | ||
// all(fn, { all }) | ||
export function all<T, U extends { all: (fn: (a: T) => boolean) => boolean }>(fn: (a: T) => boolean, obj: U): boolean; | ||
|
||
// all(__, list)(fn) | ||
export function all<T>(__: Placeholder, list: readonly T[]): (fn: (a: T) => boolean) => boolean; | ||
// all(__, { all })(fn) | ||
export function all<U extends { all: (fn: (a: any) => boolean) => boolean }>(__: Placeholder, obj: U): (fn: (a: InferAllAType<U>) => boolean) => boolean; | ||
|
||
// all (fn) | ||
export function all<T>(fn: (a: T) => boolean): { | ||
// all (fn)({ all }) | ||
<U extends { all: (fn: (a: T) => boolean) => boolean }>(obj: U): boolean; | ||
// all (fn)(list) | ||
(list: readonly T[]): boolean; | ||
// all (fn)({ all }) | ||
// <U extends { all: (fn: (a: T) => boolean) => boolean }>(obj: U): boolean;gss | ||
}; | ||
|
||
// all(__, { all })(fn) | ||
export function all<U extends { all: (fn: (a: any) => boolean) => boolean }>(__: Placeholder, obj: U): (fn: (a: InferAllAType<U>) => boolean) => boolean; | ||
// all(__, list)(fn) | ||
export function all<T>(__: Placeholder, list: readonly T[]): (fn: (a: T) => boolean) => boolean; | ||
|
||
// all(fn, { all }) | ||
export function all<T, U extends { all: (fn: (a: T) => boolean) => boolean }>(fn: (a: T) => boolean, obj: U): boolean; | ||
// all(fn, list) | ||
export function all<T>(fn: (a: T) => boolean, list: readonly T[]): boolean; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Placeholder } from './util/tools'; | ||
|
||
export function and<A>(a: A): <B>(b: B) => A | B; | ||
export function and<B>(__: Placeholder, b: B): <A>(a: A) => A | B; | ||
export function and<A, B>(a: A, b: B): A | B; | ||
export function and<A>(a: A): <B>(b: B) => A | 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Placeholder } from './util/tools'; | ||
|
||
export function andThen<A, B>(onSuccess: (a: A) => B | Promise<B>, promise: Promise<A>): Promise<B>; | ||
export function andThen<A>(__: Placeholder, promise: Promise<A>): <B>(onSuccess: (a: A) => B | Promise<B>) => Promise<B>; | ||
export function andThen<A, B>(onSuccess: (a: A) => B | Promise<B>): (promise: Promise<A>) => Promise<B>; | ||
export function andThen<A>(__: Placeholder, promise: Promise<A>): <B>(onSuccess: (a: A) => B | Promise<B>) => Promise<B>; | ||
export function andThen<A, B>(onSuccess: (a: A) => B | Promise<B>, promise: Promise<A>): Promise<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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export function ap<T, U>(fns: ReadonlyArray<(a: T) => U>, vs: readonly T[]): U[]; | ||
export function ap<T, U>(fns: ReadonlyArray<(a: T) => U>): (vs: readonly T[]) => U[]; | ||
export function ap<R, A, B>(fn: (r: R, a: A) => B, fn1: (r: R) => A): (r: R) => B; | ||
export function ap<T, U>(fns: ReadonlyArray<(a: T) => U>, vs: readonly T[]): U[]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Placeholder, Tuple } from './util/tools'; | ||
|
||
export function aperture<N extends number, T>(n: N, list: readonly T[]): Array<Tuple<T, N>> | []; | ||
export function aperture<T>(__: Placeholder, list: readonly T[]): <N extends number>(n: N) => Array<Tuple<T, N>> | []; | ||
export function aperture<N extends number>(n: N): <T>(list: readonly T[]) => Array<Tuple<T, N>> | []; | ||
export function aperture<T>(__: Placeholder, list: readonly T[]): <N extends number>(n: N) => Array<Tuple<T, N>> | []; | ||
export function aperture<N extends number, T>(n: N, list: readonly T[]): Array<Tuple<T, N>> | []; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { Placeholder } from './util/tools'; | ||
|
||
// append(el)(list) | ||
export function append<T>(el: T): (list: readonly T[]) => T[]; | ||
// append(__, list)(el) | ||
export function append<T>(__: Placeholder, list: readonly T[]): (el: T) => T[]; | ||
// append(el, list) | ||
export function append<T>(el: T, list: readonly T[]): T[]; | ||
// append(el)(list) | ||
export function append<T>(el: T): (list: readonly T[]) => T[]; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export function applyTo<T, U>(el: T, fn: (t: T) => U): U; | ||
export function applyTo<T>(el: T): <U>(fn: (t: T) => U) => U; | ||
export function applyTo<T, U>(el: T, fn: (t: T) => U): U; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Ord, Ordering } from './util/tools'; | ||
|
||
export function ascend<T>(fn: (obj: T) => Ord, a: T, b: T): Ordering; | ||
export function ascend<T>(fn: (obj: T) => Ord): (a: T, b: T) => Ordering; | ||
export function ascend<T>(fn: (obj: T) => Ord, a: T, b: T): Ordering; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import * as _ from 'ts-toolbelt'; | ||
import { Placeholder, Path } from './util/tools'; | ||
|
||
export function assocPath<T, U>(path: Path): _.F.Curry<(a: T, b: U) => U>; | ||
export function assocPath<T, U>(path: Path, val: T): (obj: U) => U; | ||
export function assocPath<T, U>(__: Placeholder, val: T, obj: U): (path: Path) => U; | ||
export function assocPath<T, U>(path: Path, __: Placeholder, obj: U): (val: T) => U; | ||
export function assocPath<T, U>(path: Path, val: T, obj: U): U; | ||
export function assocPath<T, U>(path: Path, val: T): (obj: U) => U; | ||
export function assocPath<T, U>(path: Path): _.F.Curry<(a: T, b: U) => U>; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export function bind<F extends (...args: readonly any[]) => any, T>( | ||
fn: F, | ||
thisObj: T, | ||
): (...args: Parameters<F>) => ReturnType<F>; | ||
): (thisObj: T) => (...args: Parameters<F>) => ReturnType<F>; | ||
export function bind<F extends (...args: readonly any[]) => any, T>( | ||
fn: F, | ||
): (thisObj: T) => (...args: Parameters<F>) => ReturnType<F>; | ||
thisObj: T, | ||
): (...args: Parameters<F>) => ReturnType<F>; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { PredTypeguard, Pred } from './util/tools'; | ||
|
||
export function both<T extends Pred>(pred1: T): (pred2: T) => T; | ||
export function both<T, TF1 extends T, TF2 extends T>( | ||
pred1: PredTypeguard<T, TF1>, | ||
pred2: PredTypeguard<T, TF2>, | ||
): (a: T) => a is TF1 & TF2; | ||
export function both<T extends Pred>(pred1: T, pred2: T): T; | ||
export function both<T extends Pred>(pred1: T): (pred2: T) => T; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export function clamp<T>(min: T, max: T, value: T): T; | ||
export function clamp<T>(min: T): { | ||
(max: T): (value: T) => T; | ||
(max: T, value: T): T | ||
}; | ||
export function clamp<T>(min: T, max: T): (value: T) => T; | ||
export function clamp<T>(min: T): (max: T, value: T) => T; | ||
export function clamp<T>(min: T): (max: T) => (value: T) => T; | ||
export function clamp<T>(min: T, max: T, value: T): T; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export function clone<T>(value: T): T; | ||
export function clone<T>(value: readonly T[]): T[]; | ||
export function clone<T>(value: T): T; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K, list: readonly T[]): T[][]; | ||
export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K): (list: readonly T[]) => T[][]; | ||
export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K, list: readonly T[]): T[][]; |
Oops, something went wrong.