@rimbu/proximity
Version:
Immutable ProximityMap implementation for TypeScript
77 lines • 1.83 kB
JavaScript
import { Token } from '@rimbu/base';
import { EmptyBase } from '@rimbu/collection-types/map-custom';
import { OptLazy, OptLazyOr } from '@rimbu/common';
import { Stream } from '@rimbu/stream';
/**
* Concrete empty implementation of {@link ProximityMap}.<br/>
* <br/>
* It represents an empty `ProximityMap` instance for a given context and efficiently
* creates non-empty maps when elements are added.
*
* @typeparam K - the key type
* @typeparam V - the value type
*/
export class ProximityMapEmpty extends EmptyBase {
constructor(context) {
super();
this.context = context;
}
streamKeys() {
return Stream.empty();
}
streamValues() {
return Stream.empty();
}
get(_key, otherwise) {
return OptLazy(otherwise);
}
hasKey() {
return false;
}
set(key, value) {
return this.context.from([[key, value]]);
}
addEntry(entry) {
return this.context.from([entry]);
}
addEntries(entries) {
return this.context.from(entries);
}
removeKeyAndGet() {
return undefined;
}
removeKey() {
return this;
}
removeKeys() {
return this;
}
modifyAt(atKey, options) {
if (!options.ifNew) {
return this;
}
const value = OptLazyOr(options.ifNew, Token);
if (value === Token)
return this;
return this.set(atKey, value);
}
mapValues() {
return this;
}
updateAt() {
return this;
}
toBuilder() {
return this.context.builder();
}
toString() {
return `${this.context.typeTag}()`;
}
toJSON() {
return {
dataType: this.context.typeTag,
value: [],
};
}
}
//# sourceMappingURL=Empty.mjs.map