import { DetailedResult, Result } from '../base'; import { KeyValueEntry } from './common'; import { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap'; /** * Parameters for constructing a {@link Collections.ResultMap | ResultMap}. * @public */ export interface IResultMapConstructorParams { entries?: Iterable>; } /** * Deferred constructor for the {@link Collections.ResultMap.(getOrAdd:2) | getOrAdd} method. * @public */ export type ResultMapValueFactory = (key: TK) => Result; /** * A {@link Collections.ResultMap | ResultMap} class as a `Map`-like object which * reports success or failure with additional details using the * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}. * @public */ export declare class ResultMap implements IReadOnlyResultMap { /** * Protected raw access to the inner `Map` object. * @public */ protected readonly _inner: Map; /** * Constructs a new {@link Collections.ResultMap | ResultMap}. * @param iterable - An iterable to initialize the map. */ constructor(iterable?: Iterable>); /** * Constructs a new {@link Collections.ResultMap | ResultMap}. * @param params - An optional set of parameters to configure the map. */ constructor(params: IResultMapConstructorParams); /** * Creates a new {@link Collections.ResultMap | ResultMap}. * @param elements - An optional iterable to initialize the map. * @returns `Success` with the new map, or `Failure` with error details * if an error occurred. * @public */ static create(elements: Iterable>): Result>; /** * Creates a new {@link Collections.ResultMap | ResultMap}. * @param params - An optional set of parameters to configure the map. * @returns `Success` with the new map, or `Failure` with error details * if an error occurred. * @public */ static create(params?: IResultMapConstructorParams): Result>; /** * Sets a key/value pair in the map if the key does not already exist. * @param key - The key to set. * @param value - The value to set. * @returns `Success` with the value and detail `added` if the key was added, * `Failure` with detail `exists` if the key already exists. Fails with detail * 'invalid-key' or 'invalid-value' and an error message if either is invalid. */ add(key: TK, value: TV): DetailedResult; /** * Clears the map. */ clear(): void; /** * Deletes a key from the map. * @param key - The key to delete. * @returns `Success` with the previous value and the detail 'deleted' * if the key was found and deleted, `Failure` with detail 'not-found' * if the key was not found, or with detail 'invalid-key' if the key is invalid. */ delete(key: TK): DetailedResult; /** * Returns an iterator over the map entries. * @returns An iterator over the map entries. */ entries(): IterableIterator>; /** * Calls a function for each entry in the map. * @param cb - The function to call for each entry. * @param arg - An optional argument to pass to the callback. */ forEach(cb: ResultMapForEachCb, arg?: unknown): void; /** * Gets a value from the map. * @param key - The key to retrieve. * @returns `Success` with the value and detail `exists` if the key was found, * `Failure` with detail `not-found` if the key was not found or with detail * `invalid-key` if the key is invalid. */ get(key: TK): DetailedResult; /** * Gets a value from the map, or adds a supplied value it if it does not exist. * @param key - The key to be retrieved or created. * @param value - The value to add if the key does not exist. * @returns `Success` with the value and detail `exists` if the key was found, * `Success` with the value and detail `added` if the key was not found and added. * Fails with detail 'invalid-key' or 'invalid-value' and an error message if either * is invalid. * {@label WITH_VALUE} */ getOrAdd(key: TK, value: TV): DetailedResult; /** * Gets a value from the map, or adds a value created by a factory function if it does not exist. * @param key - The key of the element to be retrieved or created. * @param factory - A {@link Collections.ResultMapValueFactory | factory function} to create the value if * the key does not exist. * @returns `Success` with the value and detail `exists` if the key was found, `Success` with * the value and detail `added` if the key was not found and added. Fails with detail 'invalid-key' * or 'invalid-value' and an error message if either is invalid. * {@label WITH_FACTORY} */ getOrAdd(key: TK, factory: ResultMapValueFactory): DetailedResult; /** * Returns `true` if the map contains a key. * @param key - The key to check. * @returns `true` if the key exists, `false` otherwise. */ has(key: TK): boolean; /** * Returns an iterator over the map keys. * @returns An iterator over the map keys. */ keys(): IterableIterator; /** * Sets a key/value pair in the map. * @param key - The key to set. * @param value - The value to set. * @returns `Success` with the new value and the detail `updated` if the * key was found and updated, `Success` with the new value and detail * `added` if the key was not found and added. Fails with detail * 'invalid-key' or 'invalid-value' and an error message if either is invalid. */ set(key: TK, value: TV): DetailedResult; /** * Returns the number of entries in the map. */ get size(): number; /** * Updates an existing key in the map - the map is not updated if the key does * not exist. * @param key - The key to update. * @param value - The value to set. * @returns `Success` with the value and detail 'exists' if the key was found * and the value updated, `Failure` an error message and with detail `not-found` * if the key was not found, or with detail 'invalid-key' or 'invalid-value' * if either is invalid. */ update(key: TK, value: TV): DetailedResult; /** * Returns an iterator over the map values. * @returns An iterator over the map values. */ values(): IterableIterator; /** * Gets an iterator over the map entries. * @returns An iterator over the map entries. */ [Symbol.iterator](): IterableIterator>; /** * Gets a readonly version of this map. * @returns A readonly version of this map. */ toReadOnly(): IReadOnlyResultMap; /** * Determines if a value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory}. * @param value - The value to check. * @returns `true` if the value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory}, * `false` otherwise. * @public */ protected _isResultMapValueFactory(value: TV | ResultMapValueFactory): value is ResultMapValueFactory; } //# sourceMappingURL=resultMap.d.ts.map