UNPKG

morphir-elm

Version:
70 lines (69 loc) 1.96 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const immutable_1 = require("immutable"); const backed_structure_1 = __importDefault(require("./backed-structure")); /** * This module has functions to help you work with morphir Sets! */ class Set extends backed_structure_1.default { /** * Create an empty list. */ static empty() { return new Set(); } /** * Create a Set from an iterable. * @param iterable the iterable to create the Set from. * @returns a new Set containing the elements from the iterable. */ static from(iterable) { return new Set(iterable); } static encoder(encoder) { return (set) => set.reduce((acc, value) => [...acc, encoder(value)], []); } static decoder(decoder) { return input => Set.from(input.map(decoder)); } constructor(iterable) { super((0, immutable_1.Set)(iterable)); } /** * Get the size of this Set. */ get size() { return this.struct.size; } /** * Get an iterator for this Set. */ get iterator() { return this.struct.values(); } add(value) { return new Set(this.struct.add(value)); } remove(value) { return new Set(this.struct.remove(value)); } union(list) { return new Set(this.struct.concat(list.struct)); } reduce(reducer, initialValue) { return this.struct.reduce(reducer, initialValue); } equals(other) { return this.struct.equals(other.struct); } hashCode() { return this.struct.hashCode(); } toString() { return `List(${JSON.stringify(this.struct.toJS())})`; } } exports.default = Set;