Created
August 30, 2017 17:14
-
-
Save apkd/2810204a45017476d63c146241af171c to your computer and use it in GitHub Desktop.
This file contains 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 { Enumerable } from "powerseq/enumerable"; | |
class KeyValuePair<T> { | |
key: string; | |
value: T; | |
} | |
class KvpDictionary<T> { | |
mapping: { [key: string]: T } = {} | |
public get keys(): Enumerable<string> { | |
return Enumerable.from(this.getKeys()); | |
} | |
public get values(): Enumerable<T> { | |
return Enumerable.from(this.getValues()); | |
} | |
public get pairs(): Enumerable<KeyValuePair<T>> { | |
return Enumerable.from(this.getPairs()); | |
} | |
private *getKeys(): Iterable<string> { | |
for (let key in this.mapping) | |
yield key; | |
} | |
private *getValues(): Iterable<T> { | |
for (let key in this.mapping) | |
yield this.mapping[key]; | |
} | |
private *getPairs(): Iterable<KeyValuePair<T>> { | |
for (let key in this.mapping) | |
yield { key: key, value: this.mapping[key] } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment