Skip to content

Instantly share code, notes, and snippets.

@sccolbert
Created October 21, 2020 19:06
Show Gist options
  • Save sccolbert/98474faad53ae3011029b7c8f67bd3b1 to your computer and use it in GitHub Desktop.
Save sccolbert/98474faad53ae3011029b7c8f67bd3b1 to your computer and use it in GitHub Desktop.
/**
* A generator function which maps a function across an iterable of values.
*/
function map(fn, items) { // Add typings to the function definition
// Implement the body of the function
}
interface HasLength {
length: number;
}
function getLength<T extends HasLength>(thing: T): number {
return thing.length;
}
// Example Usage
for (let length of map(getLength, ['cat', 'dog', 'mouse', 'canada'])) {
console.log(length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment