Last active
October 28, 2017 19:18
-
-
Save chriskrycho/3c73b05a727ad63fe790267efc2a0263 to your computer and use it in GitHub Desktop.
Discovering the need/desire for higher-kinded types in TypeScript…
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
| import Maybe from './maybe'; | |
| import Result from './result'; | |
| // This isn't valid: you can't parameterize one type with another like I do here | |
| // with M<T>, M<U> in TypeScript. | |
| type Mappable<M, T, U> = { | |
| map(this: M<T>, mapFn: (t: T) => U): M<U>; | |
| }; | |
| export const map = <T, U>(mapFn: (t: T) => U, item: Mappable<typeof item, T, U>) => item.map(mapFn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment