"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.copy = exports.lookup = exports.lookup_ = exports.removeMany = exports.removeMany_ = exports.remove = exports.remove_ = exports.insert = exports.insert_ = exports.toMutable = exports.size = exports.singleton = exports.mapWithIndex = exports.mapWithIndex_ = exports.map = exports.map_ = exports.isEmpty = exports.fromMutable = exports.filterWithIndex = exports.filterWithIndex_ = exports.filterMapWithIndex = exports.filterMapWithIndex_ = exports.filterMap = exports.filterMap_ = exports.empty = exports.compact = exports.make = void 0;
// ets_tracing: off
/* adapted from https://github.com/gcanti/fp-ts */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const Op = __importStar(require("../../../Option"));
const Option_1 = require("../../../Option");
const Tp = __importStar(require("../Tuple"));
/**
 * Create from a key-value array
 */
function make(values) {
    const map = new Map();
    for (const _ of values) {
        if (Tp.isTuple(_)) {
            map.set(_.get(0), _.get(1));
        }
        else {
            map.set(_[0], _[1]);
        }
    }
    return map;
}
exports.make = make;
/**
 * Removes None values
 */
function compact(fa) {
    const m = new Map();
    const entries = fa.entries();
    let e;
    while (!(e = entries.next()).done) {
        const [k, oa] = e.value;
        if (Op.isSome(oa)) {
            m.set(k, oa.value);
        }
    }
    return m;
}
exports.compact = compact;
/**
 * Empty Map
 */
exports.empty = new Map();
/**
 * Filter out None and map
 */
function filterMap_(fa, f) {
    return filterMapWithIndex_(fa, (_, a) => f(a));
}
exports.filterMap_ = filterMap_;
/**
 * Filter out None and map
 */
function filterMap(f) {
    return (fa) => filterMap_(fa, f);
}
exports.filterMap = filterMap;
/**
 * Filter out None and map
 */
function filterMapWithIndex_(fa, f) {
    const m = new Map();
    const entries = fa.entries();
    let e;
    // tslint:disable-next-line: strict-boolean-expressions
    while (!(e = entries.next()).done) {
        const [k, a] = e.value;
        const o = f(k, a);
        if (Op.isSome(o)) {
            m.set(k, o.value);
        }
    }
    return m;
}
exports.filterMapWithIndex_ = filterMapWithIndex_;
/**
 * Filter out None and map
 */
function filterMapWithIndex(f) {
    return (fa) => filterMapWithIndex_(fa, f);
}
exports.filterMapWithIndex = filterMapWithIndex;
/**
 * Filter out None and map
 */
function filterWithIndex_(fa, p) {
    const m = new Map();
    const entries = fa.entries();
    let e;
    // tslint:disable-next-line: strict-boolean-expressions
    while (!(e = entries.next()).done) {
        const [k, a] = e.value;
        if (p(k, a)) {
            m.set(k, a);
        }
    }
    return m;
}
exports.filterWithIndex_ = filterWithIndex_;
/**
 * Filter out None and map
 */
function filterWithIndex(p) {
    return (fa) => filterWithIndex_(fa, p);
}
exports.filterWithIndex = filterWithIndex;
/**
 * Construct a new Readonly Map
 */
function fromMutable(m) {
    return new Map(m);
}
exports.fromMutable = fromMutable;
/**
 * Test whether or not a map is empty
 */
function isEmpty(d) {
    return d.size === 0;
}
exports.isEmpty = isEmpty;
/**
 * Maps values using f
 */
function map_(fa, f) {
    return mapWithIndex_(fa, (_, a) => f(a));
}
exports.map_ = map_;
/**
 * Maps values using f
 */
function map(f) {
    return (fa) => map_(fa, f);
}
exports.map = map;
/**
 * Maps values using f
 */
function mapWithIndex_(fa, f) {
    const m = new Map();
    const entries = fa.entries();
    let e;
    while (!(e = entries.next()).done) {
        const [key, a] = e.value;
        m.set(key, f(key, a));
    }
    return m;
}
exports.mapWithIndex_ = mapWithIndex_;
/**
 * Maps values using f
 */
function mapWithIndex(f) {
    return (fa) => mapWithIndex_(fa, f);
}
exports.mapWithIndex = mapWithIndex;
/**
 * Create a map with one key/value pair
 */
function singleton(k, a) {
    return new Map([[k, a]]);
}
exports.singleton = singleton;
/**
 * Calculate the number of key/value pairs in a map
 */
function size(d) {
    return d.size;
}
exports.size = size;
/**
 * Construct a new mutable map by copying this one
 */
function toMutable(m) {
    return new Map(m);
}
exports.toMutable = toMutable;
function insert_(self, k, v) {
    const m = copy(self);
    m.set(k, v);
    return m;
}
exports.insert_ = insert_;
function insert(k, v) {
    return (self) => insert_(self, k, v);
}
exports.insert = insert;
function remove_(self, k) {
    const m = copy(self);
    m.delete(k);
    return m;
}
exports.remove_ = remove_;
function remove(k) {
    return (self) => remove_(self, k);
}
exports.remove = remove;
function removeMany_(self, ks) {
    const m = copy(self);
    for (const k of ks) {
        m.delete(k);
    }
    return m;
}
exports.removeMany_ = removeMany_;
function removeMany(ks) {
    return (self) => removeMany_(self, ks);
}
exports.removeMany = removeMany;
function lookup_(m, k) {
    return (0, Option_1.fromNullable)(m.get(k));
}
exports.lookup_ = lookup_;
function lookup(k) {
    return (m) => lookup_(m, k);
}
exports.lookup = lookup;
function copy(self) {
    const m = new Map();
    self.forEach((v, k) => {
        m.set(k, v);
    });
    return m;
}
exports.copy = copy;
//# sourceMappingURL=core.js.map