Skip to content

Instantly share code, notes, and snippets.

@johnhaley81
Created March 6, 2019 18:50
Show Gist options
  • Save johnhaley81/f9fe31d5e4ee071a07f5aebca8b0013f to your computer and use it in GitHub Desktop.
Save johnhaley81/f9fe31d5e4ee071a07f5aebca8b0013f to your computer and use it in GitHub Desktop.
Reason bindings vs TypeScript types
export as namespace Reselect;
export type Selector<S, R> = (state: S) => R;
export type OutputSelector<S, R, C> = Selector<S, R> & {
resultFunc: C;
recomputations: () => number;
resetRecomputations: () => number;
}
export function createSelector<S, R1, T>(
selector: Selector<S, R1>,
combiner: (res: R1) => T,
): OutputSelector<S, T, (res: R1) => T>;
export function createSelector<S, P, R1, T>(
selector: ParametricSelector<S, P, R1>,
combiner: (res: R1) => T,
): OutputParametricSelector<S, P, T, (res: R1) => T>;
export function createSelector<S, R1, R2, T>(
selector1: Selector<S, R1>,
selector2: Selector<S, R2>,
combiner: (res1: R1, res2: R2) => T,
): OutputSelector<S, T, (res1: R1, res2: R2) => T>;
export function createSelector<S, P, R1, R2, T>(
selector1: ParametricSelector<S, P, R1>,
selector2: ParametricSelector<S, P, R2>,
combiner: (res1: R1, res2: R2) => T,
): OutputParametricSelector<S, P, T, (res1: R1, res2: R2) => T>;
export function createSelector<S, R1, R2, R3, T>(
selector1: Selector<S, R1>,
selector2: Selector<S, R2>,
selector3: Selector<S, R3>,
combiner: (res1: R1, res2: R2, res3: R3) => T,
): OutputSelector<S, T, (res1: R1, res2: R2, res3: R3) => T>;
export function createSelector<S, P, R1, R2, R3, T>(
selector1: ParametricSelector<S, P, R1>,
selector2: ParametricSelector<S, P, R2>,
selector3: ParametricSelector<S, P, R3>,
combiner: (res1: R1, res2: R2, res3: R3) => T,
): OutputParametricSelector<S, P, T, (res1: R1, res2: R2, res3: R3) => T>;
export function createSelector<S, R1, R2, R3, R4, T>(
selector1: Selector<S, R1>,
selector2: Selector<S, R2>,
selector3: Selector<S, R3>,
selector4: Selector<S, R4>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4) => T,
): OutputSelector<S, T, (res1: R1, res2: R2, res3: R3, res4: R4) => T>;
export function createSelector<S, P, R1, R2, R3, R4, T>(
selector1: ParametricSelector<S, P, R1>,
selector2: ParametricSelector<S, P, R2>,
selector3: ParametricSelector<S, P, R3>,
selector4: ParametricSelector<S, P, R4>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4) => T,
): OutputParametricSelector<S, P, T, (res1: R1, res2: R2, res3: R3, res4: R4) => T>;
export function createSelector<S, R1, R2, R3, R4, R5, T>(
selector1: Selector<S, R1>,
selector2: Selector<S, R2>,
selector3: Selector<S, R3>,
selector4: Selector<S, R4>,
selector5: Selector<S, R5>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5) => T,
): OutputSelector<S, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5) => T>;
export function createSelector<S, P, R1, R2, R3, R4, R5, T>(
selector1: ParametricSelector<S, P, R1>,
selector2: ParametricSelector<S, P, R2>,
selector3: ParametricSelector<S, P, R3>,
selector4: ParametricSelector<S, P, R4>,
selector5: ParametricSelector<S, P, R5>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5) => T,
): OutputParametricSelector<S, P, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5) => T>;
export function createSelector<S, R1, R2, R3, R4, R5, R6, T>(
selector1: Selector<S, R1>,
selector2: Selector<S, R2>,
selector3: Selector<S, R3>,
selector4: Selector<S, R4>,
selector5: Selector<S, R5>,
selector6: Selector<S, R6>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6) => T,
): OutputSelector<S, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6) => T>;
export function createSelector<S, P, R1, R2, R3, R4, R5, R6, T>(
selector1: ParametricSelector<S, P, R1>,
selector2: ParametricSelector<S, P, R2>,
selector3: ParametricSelector<S, P, R3>,
selector4: ParametricSelector<S, P, R4>,
selector5: ParametricSelector<S, P, R5>,
selector6: ParametricSelector<S, P, R6>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6) => T,
): OutputParametricSelector<S, P, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6) => T>;
export function createSelector<S, R1, R2, R3, R4, R5, R6, R7, T>(
selector1: Selector<S, R1>,
selector2: Selector<S, R2>,
selector3: Selector<S, R3>,
selector4: Selector<S, R4>,
selector5: Selector<S, R5>,
selector6: Selector<S, R6>,
selector7: Selector<S, R7>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7) => T,
): OutputSelector<S, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7) => T>;
export function createSelector<S, P, R1, R2, R3, R4, R5, R6, R7, T>(
selector1: ParametricSelector<S, P, R1>,
selector2: ParametricSelector<S, P, R2>,
selector3: ParametricSelector<S, P, R3>,
selector4: ParametricSelector<S, P, R4>,
selector5: ParametricSelector<S, P, R5>,
selector6: ParametricSelector<S, P, R6>,
selector7: ParametricSelector<S, P, R7>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7) => T,
): OutputParametricSelector<S, P, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7) => T>;
export function createSelector<S, R1, R2, R3, R4, R5, R6, R7, R8, T>(
selector1: Selector<S, R1>,
selector2: Selector<S, R2>,
selector3: Selector<S, R3>,
selector4: Selector<S, R4>,
selector5: Selector<S, R5>,
selector6: Selector<S, R6>,
selector7: Selector<S, R7>,
selector8: Selector<S, R8>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7, res8: R8) => T,
): OutputSelector<S, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7, res8: R8) => T>;
export function createSelector<S, P, R1, R2, R3, R4, R5, R6, R7, R8, T>(
selector1: ParametricSelector<S, P, R1>,
selector2: ParametricSelector<S, P, R2>,
selector3: ParametricSelector<S, P, R3>,
selector4: ParametricSelector<S, P, R4>,
selector5: ParametricSelector<S, P, R5>,
selector6: ParametricSelector<S, P, R6>,
selector7: ParametricSelector<S, P, R7>,
selector8: ParametricSelector<S, P, R8>,
combiner: (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7, res8: R8) => T,
): OutputParametricSelector<S, P, T, (res1: R1, res2: R2, res3: R3, res4: R4, res5: R5, res6: R6,
res7: R7, res8: R8) => T>;
type selector('state, 'result) = 'state => 'result;
[@bs.module "reselect"]
external createSelector1:
('state => 'a, 'a => 'result) => selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector2:
('state => 'a, 'state => 'b, ('a, 'b) => 'result) =>
selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector3:
('state => 'a, 'state => 'b, 'state => 'c, ('a, 'b, 'c) => 'result) =>
selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector4:
(
'state => 'a,
'state => 'b,
'state => 'c,
'state => 'd,
('a, 'b, 'c, 'd) => 'result
) =>
selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector5:
(
'state => 'a,
'state => 'b,
'state => 'c,
'state => 'd,
'state => 'e,
('a, 'b, 'c, 'd, 'e) => 'result
) =>
selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector6:
(
'state => 'a,
'state => 'b,
'state => 'c,
'state => 'd,
'state => 'e,
'state => 'f,
('a, 'b, 'c, 'd, 'e, 'f) => 'result
) =>
selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector7:
(
'state => 'a,
'state => 'b,
'state => 'c,
'state => 'd,
'state => 'e,
'state => 'f,
'state => 'g,
('a, 'b, 'c, 'd, 'e, 'f, 'g) => 'result
) =>
selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector8:
(
'state => 'a,
'state => 'b,
'state => 'c,
'state => 'd,
'state => 'e,
'state => 'f,
'state => 'g,
'state => 'h,
('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h) => 'result
) =>
selector('state, 'result) =
"createSelector";
@johnhaley81
Copy link
Author

Just a comparison between writing bindings in Reason vs writing types in TypeScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment