Skip to content

Instantly share code, notes, and snippets.

@chriskrycho
Last active October 28, 2017 19:18
Show Gist options
  • Save chriskrycho/3c73b05a727ad63fe790267efc2a0263 to your computer and use it in GitHub Desktop.
Save chriskrycho/3c73b05a727ad63fe790267efc2a0263 to your computer and use it in GitHub Desktop.
Discovering the need/desire for higher-kinded types in TypeScript…
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