Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into groupby-partial
Browse files Browse the repository at this point in the history
* 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
jeysal committed Jun 28, 2023
2 parents 46bf279 + edea784 commit 99ee949
Show file tree
Hide file tree
Showing 168 changed files with 547 additions and 362 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

1. Run `npm install` to install needed local dependencies.

1. Run `npm run build` first, then `npm run test` and address any errors. Preferably, fix commits in place
1. Run `npm run build` first, then `npm run test` and `npm run lint` and address any errors. Preferably, fix commits in place
using `git rebase` or `git commit --amend` to make the changes easier to
review and to keep the history tidy.

1. Push to your fork:

$ git push origin <branch>

2. Open a pull request.
1. Open a pull request.

TODO: Explain the convention for creating types for ramda
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"eslint-plugin-import": "^2.27.5",
"ramda": "^0.29.0",
"tsd": "^0.28.1",
"typescript": "^5.0.2",
"typescript": "^5.1.3",
"xyz": "^4.0.0"
}
}
11 changes: 11 additions & 0 deletions test/count.test.ts
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));
50 changes: 50 additions & 0 deletions test/of.test.ts
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>);
30 changes: 30 additions & 0 deletions test/swap.test.ts
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)));
2 changes: 1 addition & 1 deletion types/add.d.ts
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;
41 changes: 29 additions & 12 deletions types/adjust.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Placeholder } from './util/tools';

// adjust(index, fn, list)
export function adjust<T>(index: number, fn: (a: T) => T, list: readonly T[]): T[];
// adjust(index, fn)(list)
export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];
// adjust(index)
export function adjust(index: number): {
// adjust(index)(fn, list)
Expand All @@ -14,16 +10,37 @@ export function adjust(index: number): {
<T>(fn: (a: T) => T): (list: readonly T[]) => T[];
};

// adjust(__, fn, list)(index)
export function adjust<T>(__: Placeholder, fn: (a: T) => T, list: readonly T[]): (index: number) => T[];
// adjust(index, __, list)(fn)
export function adjust<T>(index: number, __: Placeholder, list: readonly T[]): (fn: (a: T) => T) => T[];
// adjust(__, fn)
export function adjust<T>(__: Placeholder, fn: (a: T) => T): {
// adjust(__, fn)(list)(index)
(list: readonly T[]): (index: number) => T[];
// adjust(__, fn)(__, index)(list)
(__: Placeholder, index: number): (list: readonly T[]) => T[];
// adjust(__, fn)(list, index)
(list: readonly T[], index: number): T[];
};

export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];

// adjust(index, fn)(list)
export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];
// adjust(index, fn)(list)
export function adjust<T>(index: number, fn: (a: T) => T): (list: readonly T[]) => T[];


// adjust(__, __, list)
export function adjust<T>(__: Placeholder, __2: Placeholder, list: readonly T[]): {
// adjust(__, __, list)(index, fn)
(index: number, fn: (a: T) => T): T[];
// adjust(__, __, list)(__, fn)(index)
(__3: Placeholder, fn: (a: T) => T): (index: number) => T[];
// adjust(__, __, list)(index)(fn)
(index: number): (fn: (a: T) => T) => T[];
// adjust(__, __, list)(__, fn)(index)
(__3: Placeholder, fn: (a: T) => T): (index: number) => T[];
// adjust(__, __, list)(index, fn)
(index: number, fn: (a: T) => T): T[];
};
// adjust(index, __, list)(fn)
export function adjust<T>(index: number, __: Placeholder, list: readonly T[]): (fn: (a: T) => T) => T[];
// adjust(__, fn, list)(index)
export function adjust<T>(__: Placeholder, fn: (a: T) => T, list: readonly T[]): (index: number) => T[];

// adjust(index, fn, list)
export function adjust<T>(index: number, fn: (a: T) => T, list: readonly T[]): T[];
24 changes: 12 additions & 12 deletions types/all.d.ts
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;
2 changes: 1 addition & 1 deletion types/and.d.ts
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;
4 changes: 2 additions & 2 deletions types/andThen.d.ts
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>;
19 changes: 9 additions & 10 deletions types/any.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { Placeholder, InferAnyAType } from './util/tools';

// any(fn, list)
export function any<T>(fn: (a: T) => boolean, list: readonly T[]): boolean;
// any(fn, { any })
export function any<T, U extends { any: (fn: (a: T) => boolean) => boolean }>(fn: (a: T) => boolean, obj: U): boolean;

// any(__, list)(fn)
export function any<T>(__: Placeholder, list: readonly T[]): (fn: (a: T) => boolean) => boolean;
// any(__, { any })(fn)
export function any<U extends { any: (fn: (a: any) => boolean) => boolean }>(___: Placeholder, obj: U): (fn: (a: InferAnyAType<U>) => boolean) => boolean;

// all(fn)
export function any<T>(fn: (a: T) => boolean): {
// any(fn)(list)
Expand All @@ -18,3 +8,12 @@ export function any<T>(fn: (a: T) => boolean): {
<U extends { any: (fn: (a: T) => boolean) => boolean }>(obj: U): boolean;
};

// any(__, list)(fn)
export function any<T>(__: Placeholder, list: readonly T[]): (fn: (a: T) => boolean) => boolean;
// any(__, { any })(fn)
export function any<U extends { any: (fn: (a: any) => boolean) => boolean }>(___: Placeholder, obj: U): (fn: (a: InferAnyAType<U>) => boolean) => boolean;

// any(fn, list)
export function any<T>(fn: (a: T) => boolean, list: readonly T[]): boolean;
// any(fn, { any })
export function any<T, U extends { any: (fn: (a: T) => boolean) => boolean }>(fn: (a: T) => boolean, obj: U): boolean;
2 changes: 1 addition & 1 deletion types/ap.d.ts
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[];
4 changes: 2 additions & 2 deletions types/aperture.d.ts
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>> | [];
4 changes: 2 additions & 2 deletions types/append.d.ts
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[];
4 changes: 2 additions & 2 deletions types/apply.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Placeholder } from './util/tools';

// apply(args)(fn)
export function apply<F extends (...args: readonly any[]) => any>(fn: F): (args: Parameters<F>) => ReturnType<F>;
// apply(args, fn)
// overload Placeholder options with versions for 1-to-5 args for best constraining
export function apply<A extends readonly [any]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
Expand All @@ -10,5 +12,3 @@ export function apply<A extends readonly [any, any, any, any, any]>(__: Placehol
export function apply<A extends readonly any[]>(__: Placeholder, args: A): <F extends (...args: A) => any>(fn: F) => ReturnType<F>;
// apply(args, fn)
export function apply<F extends (...args: readonly any[]) => any>(fn: F, args: Parameters<F>): ReturnType<F>;
// apply(args)(fn)
export function apply<F extends (...args: readonly any[]) => any>(fn: F): (args: Parameters<F>) => ReturnType<F>;
2 changes: 1 addition & 1 deletion types/applyTo.d.ts
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;
2 changes: 1 addition & 1 deletion types/ascend.d.ts
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;
4 changes: 2 additions & 2 deletions types/assocPath.d.ts
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>;
6 changes: 3 additions & 3 deletions types/bind.d.ts
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>;
2 changes: 1 addition & 1 deletion types/both.d.ts
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;
8 changes: 5 additions & 3 deletions types/clamp.d.ts
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;
2 changes: 1 addition & 1 deletion types/clone.d.ts
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;
2 changes: 1 addition & 1 deletion types/collectBy.d.ts
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[][];
Loading

0 comments on commit 99ee949

Please sign in to comment.