Created
August 22, 2018 11:40
-
-
Save mvaldesdeleon/b27bbf36f7739843e6b4cf1678b6a94e to your computer and use it in GitHub Desktop.
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 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