Skip to content

Instantly share code, notes, and snippets.

@mvaldesdeleon
Created August 22, 2018 11:40
Show Gist options
  • Save mvaldesdeleon/b27bbf36f7739843e6b4cf1678b6a94e to your computer and use it in GitHub Desktop.
Save mvaldesdeleon/b27bbf36f7739843e6b4cf1678b6a94e to your computer and use it in GitHub Desktop.
function mapCompose<A, B, C>(mab: Map<A, B>, mbc: Map<B, C>): Map<A, C> {
const mac: Map<A, C> = new Map();
mab.forEach((value, key) => {
const finalValue = mbc.get(value);
if (finalValue !== undefined) {
mac.set(key, finalValue);
}
});
return mac;
}
const mab: Map<number, string> = new Map();
const mbc: Map<string, boolean> = new Map();
mab.set(0, 'zero');
mab.set(1, 'one');
mab.set(3, 'three');
mbc.set('zero', true);
mbc.set('two', false);
mbc.set('three', false);
const mac = mapCompose(mab, mbc);
console.log(mac.get(0))
console.log(mac.get(1))
console.log(mac.get(2))
console.log(mac.get(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment