Skip to content

Commit

Permalink
refactor: improve type declarations for group function using generics
Browse files Browse the repository at this point in the history
  • Loading branch information
rajutkarsh07 committed Feb 25, 2024
1 parent 31aff93 commit af1b180
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions lib/node_modules/@stdlib/utils/group/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,73 +23,73 @@
import { Collection } from '@stdlib/types/array';

/**
* Interface defining function options.
*/
* Interface defining function options.
*/
interface Options {
/**
* If `'values'`, values are returned; if `'indices'`, indices are returned; if `'*'`, both indices and values are returned.
*/
* If `'values'`, values are returned; if `'indices'`, indices are returned; if `'*'`, both indices and values are returned.
*/
returns?: 'values' | 'indices' | '*';
}

/**
* Groups values as arrays associated with distinct keys.
*
* ## Notes
*
* - If provided an empty collection, the function returns an empty object.
*
* @param collection - collection to group
* @param groups - collection defining which group an element in the input collection belongs to
* @throws first and last arguments must be the same length
* @returns group results
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var groups = [ 'b', 'b', 'f', 'b' ];
*
* var out = group( arr, groups );
* // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
*/
declare function group( collection: Collection, groups: Collection ): any;
* Groups values as arrays associated with distinct keys.
*
* ## Notes
*
* - If provided an empty collection, the function returns an empty object.
*
* @param collection - collection to group
* @param groups - collection defining which group an element in the input collection belongs to
* @throws first and last arguments must be the same length
* @returns group results
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var groups = [ 'b', 'b', 'f', 'b' ];
*
* var out = group( arr, groups );
* // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
*/
declare function group<T>( collection: Collection<T>, groups: Collection<T> ): { [key: string]: Collection<T> };

/**
* Groups values as arrays associated with distinct keys.
*
* ## Notes
*
* - If provided an empty collection, the function returns an empty object.
*
* @param collection - collection to group
* @param options - function options
* @param options.returns - if `values`, values are returned; if `indices`, indices are returned; if `*`, both indices and values are returned (default: 'values')
* @param groups - collection defining which group an element in the input collection belongs to
* @throws first and last arguments must be the same length
* @returns group results
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var groups = [ 'b', 'b', 'f', 'b' ];
*
* var opts = {
* 'returns': 'indices'
* };
*
* var out = group( arr, opts, groups );
* // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var groups = [ 'b', 'b', 'f', 'b' ];
*
* var opts = {
* 'returns': '*'
* };
*
* var out = group( arr, opts, groups );
* // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }
*/
declare function group( collection: Collection, options: Options, groups: Collection ): any;
* Groups values as arrays associated with distinct keys.
*
* ## Notes
*
* - If provided an empty collection, the function returns an empty object.
*
* @param collection - collection to group
* @param options - function options
* @param options.returns - if `values`, values are returned; if `indices`, indices are returned; if `*`, both indices and values are returned (default: 'values')
* @param groups - collection defining which group an element in the input collection belongs to
* @throws first and last arguments must be the same length
* @returns group results
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var groups = [ 'b', 'b', 'f', 'b' ];
*
* var opts = {
* 'returns': 'indices'
* };
*
* var out = group( arr, opts, groups );
* // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }
*
* @example
* var arr = [ 'beep', 'boop', 'foo', 'bar' ];
* var groups = [ 'b', 'b', 'f', 'b' ];
*
* var opts = {
* 'returns': '*'
* };
*
* var out = group( arr, opts, groups );
* // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }
*/
declare function group<T>( collection: Collection<T>, options: Options, groups: Collection<T> ): { [key: string]: Collection<T>};


// EXPORTS //
Expand Down

0 comments on commit af1b180

Please sign in to comment.