import { AsyncMapper, Mapper } from 'augmentative-iterable'; import { ToObjectKeyType } from '../base'; import { Choose } from '../choose'; export type ObjectType = { [k in R]: unknown; }; export type KeyType = string | symbol | number; export interface ToObjectFunction { /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by a key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable.
* Examples:
* * `fluent(['anchor', 'almond']).toObject(word => word)` returns `{ anchor: 'anchor', almond: 'almond' }` * * `fluent([{ key: 'name', value: 'Peter Parker' }, { key: 'alias', value: 'SpiderMan' }]).toObject(item => item.key, item => item.value)` returns `{ name: 'Peter Parker', alias: 'SpiderMan' }` * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Projects an element of the iterable into the key of the corresponding field. * @returns The object composed of the elements of the iterable as fields. */ (keySelector: Mapper): Record; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by a key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable.
* Examples:
* * `fluent(['anchor', 'almond']).toObject(word => word)` returns `{ anchor: 'anchor', almond: 'almond' }` * * `fluent([{ key: 'name', value: 'Peter Parker' }, { key: 'alias', value: 'SpiderMan' }]).toObject(item => item.key, item => item.value)` returns `{ name: 'Peter Parker', alias: 'SpiderMan' }` * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Projects an element of the iterable into the key of the corresponding field. * @param valueSelector Projects an element of the iterable into the value of the corresponding field. The identity function is being used if omitted. * @returns The object composed of the elements of the iterable as fields. */ (keySelector: Mapper, valueSelector: Mapper, reduceValue?: Choose): Record; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by a key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable.
* Examples:
* @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Projects an element of the iterable into the key of the corresponding field. * @returns The object composed of the elements of the iterable as fields. */ (keySelector: R1): Record, T>; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by a key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable.
* Examples:
* * `fluent(['anchor', 'almond']).toObject(word => word)` returns `{ anchor: 'anchor', almond: 'almond' }` * * `fluent([{ key: 'name', value: 'Peter Parker' }, { key: 'alias', value: 'SpiderMan' }]).toObject(item => item.key, item => item.value)` returns `{ name: 'Peter Parker', alias: 'SpiderMan' }` * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Projects an element of the iterable into the key of the corresponding field. * @param valueSelector Projects an element of the iterable into the value of the corresponding field. The identity function is being used if omitted. * @returns The object composed of the elements of the iterable as fields. */ (keySelector: R1, valueSelector: Mapper, reduceValue?: Choose): Record, R>; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by a key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable.
* Examples:
* * `fluent(['anchor', 'almond']).toObject(word => word)` returns `{ anchor: 'anchor', almond: 'almond' }` * * `fluent([{ key: 'name', value: 'Peter Parker' }, { key: 'alias', value: 'SpiderMan' }]).toObject(item => item.key, item => item.value)` returns `{ name: 'Peter Parker', alias: 'SpiderMan' }` * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Projects an element of the iterable into the key of the corresponding field. * @param valueSelector Projects an element of the iterable into the value of the corresponding field. The identity function is being used if omitted. * @returns The object composed of the elements of the iterable as fields. */ (keySelector: Mapper, valueSelector: R2, reduceValue?: Choose): Record; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by a key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable.
* Examples:
* * `fluent(['anchor', 'almond']).toObject(word => word)` returns `{ anchor: 'anchor', almond: 'almond' }` * * `fluent([{ key: 'name', value: 'Peter Parker' }, { key: 'alias', value: 'SpiderMan' }]).toObject(item => item.key, item => item.value)` returns `{ name: 'Peter Parker', alias: 'SpiderMan' }` * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Projects an element of the iterable into the key of the corresponding field. * @param valueSelector Projects an element of the iterable into the value of the corresponding field. The identity function is being used if omitted. * @returns The object composed of the elements of the iterable as fields. */ (keySelector: R1, valueSelector: R2, reduceValue?: Choose): Record, T[R2]>; } export interface AsyncToObjectFunction { /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by an asynchronous key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable. * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Asynchronously projects an element of the iterable into the key of the corresponding field. * @returns A promise of the object composed of the elements of the iterable as fields. */ (keySelector: AsyncMapper): Promise>; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by an asynchronous key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable. * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Asynchronously projects an element of the iterable into the key of the corresponding field. * @param valueSelector Asynchronously projects an element of the iterable into the value of the corresponding field. * @param reduceValue reduce the following items to the map value type. If not informed, assumes only the first value * @returns A promise of the object composed of the elements of the iterable as fields. */ (keySelector: AsyncMapper, valueSelector: AsyncMapper, reduceValue?: Choose): Promise>; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by an asynchronous key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable. * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Asynchronously projects an element of the iterable into the key of the corresponding field. * @returns A promise of the object composed of the elements of the iterable as fields. */ (keySelector: R1): Promise, T>>; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by an asynchronous key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable. * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Asynchronously projects an element of the iterable into the key of the corresponding field. * @param valueSelector Asynchronously projects an element of the iterable into the value of the corresponding field. * @param reduceValue reduce the following items to the map value type. If not informed, assumes only the first value * @returns A promise of the object composed of the elements of the iterable as fields. */ (keySelector: R1, valueSelector: AsyncMapper, reduceValue?: Choose): Promise, R>>; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by an asynchronous key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable. * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Asynchronously projects an element of the iterable into the key of the corresponding field. * @param valueSelector Asynchronously projects an element of the iterable into the value of the corresponding field. * @param reduceValue reduce the following items to the map value type. If not informed, assumes only the first value * @returns A promise of the object composed of the elements of the iterable as fields. */ (keySelector: AsyncMapper, valueSelector: R2, reduceValue?: Choose): Promise>; /** * Translates the iterable into an object using the elements of the iterable as representations of fields as specified by an asynchronous key- and value selector. This is a resolving operation, will cause a full loop through all the elements of the iterable. * @typeparam R The expected type of the object. Cannot be enforced, this is strictly informal. * @param keySelector Asynchronously projects an element of the iterable into the key of the corresponding field. * @param valueSelector Asynchronously projects an element of the iterable into the value of the corresponding field. * @param reduceValue reduce the following items to the map value type. If not informed, assumes only the first value * @returns A promise of the object composed of the elements of the iterable as fields. */ (keySelector: R1, valueSelector: R2, reduceValue?: Choose): Promise, T[R2]>>; }