UNPKG

scats

Version:

Useful scala classes in typescript

60 lines (59 loc) 1.5 kB
import { ArrayIterable } from './array-iterable.js'; import { option } from './option.js'; import { HashSet } from './hashset.js'; import { Collection } from './collection.js'; export class AbstractMap extends ArrayIterable { map; constructor(map) { super(); this.map = map; } get size() { return this.map.size; } get isEmpty() { return this.map.size <= 0; } get(key) { return option(this.map.get(key)); } getOrElse(key, defaultValue) { return this.get(key).getOrElse(defaultValue); } getOrElseValue(key, defaultValue) { return this.get(key).getOrElseValue(defaultValue); } get keySet() { return HashSet.of(...Array.from(this.map.keys())); } get keyIterator() { return this.map.keys(); } get keys() { return new Collection(Array.from(this.map.keys())); } get values() { return new Collection(Array.from(this.map.values())); } get valueIterator() { return this.map.values(); } get entries() { return new Collection(Array.from(this.map.entries())); } get entriesIterator() { return this.map.entries(); } containsKey(key) { return this.map.has(key); } get toCollection() { return new Collection(Array.from(this.map.entries())); } get toMap() { return this.map; } get toArray() { return Array.from(this.map.entries()); } }