Created
July 30, 2018 06:13
-
-
Save tswistak/bb95a8bbb3a34515ec6cac7d7f120ace to your computer and use it in GitHub Desktop.
TypeScript 3.0, listing 6
This file contains hidden or 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
| function compose2<T1 extends any[], T1R, T2>(f1: (...args1: T1) => T1R, f2: (arg: T1R) => T2) { | |
| return (...a: T1) => f2(f1(...a)); | |
| } | |
| const add = (x: number, y: number) => x + y; | |
| const sqr = (x: number) => x * x; | |
| const addAndSqr = compose2(add, sqr); | |
| addAndSqr(1, 2); // valid | |
| addAndSqr('a', 2); // invalid type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment