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 Set<T> { [IsSet]: boolean; }
|
||||||
interface SetConstructor { isSet<T>(x: any): x is Set<T>; }
|
interface SetConstructor { isSet<T>(x: any): x is Set<T>; }
|
||||||
}
|
}
|
||||||
Object.defineProperty(Map.prototype, IsMap, { get() { return true; } });
|
if (!(IsMap in Map.prototype)) {
|
||||||
Map.isMap = <K,V> (x: any): x is Map<K, V> => !!x?.[IsMap];
|
Object.defineProperty(Map.prototype, IsMap, { get() { return true; } });
|
||||||
Object.defineProperty(Set.prototype, IsSet, { get() { return true; } });
|
Map.isMap = <K,V> (x: any): x is Map<K, V> => !!x?.[IsMap];
|
||||||
Set.isSet = <T> (x: any): x is Set<T> => !!x?.[IsSet];
|
}
|
||||||
|
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> {
|
export function _iterMap<S,T>(i: Iterator<S>, f : (s: S) => T): IterableIterator<T> {
|
||||||
const _f = (r: IteratorResult<S>): IteratorResult<T> => {
|
const _f = (r: IteratorResult<S>): IteratorResult<T> => {
|
||||||
|
|
Loading…
Reference in New Issue