Idempotent Map/Set extensions
This commit is contained in:
parent
0bb61d260f
commit
abca13e260
|
@ -31,10 +31,14 @@ declare global {
|
|||
interface Set<T> { [IsSet]: boolean; }
|
||||
interface SetConstructor { isSet<T>(x: any): x is Set<T>; }
|
||||
}
|
||||
Object.defineProperty(Map.prototype, IsMap, { get() { return true; } });
|
||||
Map.isMap = <K,V> (x: any): x is Map<K, V> => !!x?.[IsMap];
|
||||
Object.defineProperty(Set.prototype, IsSet, { get() { return true; } });
|
||||
Set.isSet = <T> (x: any): x is Set<T> => !!x?.[IsSet];
|
||||
if (!(IsMap in Map.prototype)) {
|
||||
Object.defineProperty(Map.prototype, IsMap, { get() { return true; } });
|
||||
Map.isMap = <K,V> (x: any): x is Map<K, V> => !!x?.[IsMap];
|
||||
}
|
||||
if (!(IsSet in Set.prototype)) {
|
||||
Object.defineProperty(Set.prototype, IsSet, { get() { return true; } });
|
||||
Set.isSet = <T> (x: any): x is Set<T> => !!x?.[IsSet];
|
||||
}
|
||||
|
||||
export function _iterMap<S,T>(i: Iterator<S>, f : (s: S) => T): IterableIterator<T> {
|
||||
const _f = (r: IteratorResult<S>): IteratorResult<T> => {
|
||||
|
|
Loading…
Reference in New Issue