Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jun 27, 2023
1 parent 30ca7e4 commit fe36ece
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 110 deletions.
18 changes: 9 additions & 9 deletions until-each-right/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type NullaryPredicate = () => boolean;
* @param value - collection value
* @returns boolean indicating whether an element in a collection passes a test
*/
type UnaryPredicate = ( value: any ) => boolean;
type UnaryPredicate<T> = ( value: T ) => boolean;

/**
* Checks whether an element in a collection passes a test.
Expand All @@ -44,7 +44,7 @@ type UnaryPredicate = ( value: any ) => boolean;
* @param index - collection index
* @returns boolean indicating whether an element in a collection passes a test
*/
type BinaryPredicate = ( value: any, index: number ) => boolean;
type BinaryPredicate<T> = ( value: T, index: number ) => boolean;

/**
* Checks whether an element in a collection passes a test.
Expand All @@ -54,7 +54,7 @@ type BinaryPredicate = ( value: any, index: number ) => boolean;
* @param collection - input collection
* @returns boolean indicating whether an element in a collection passes a test
*/
type TernaryPredicate = ( value: any, index: number, collection: Collection ) => boolean; // tslint-disable-line max-line-length
type TernaryPredicate<T> = ( value: T, index: number, collection: Collection<T> ) => boolean; // tslint-disable-line max-line-length

/**
* Checks whether an element in a collection passes a test.
Expand All @@ -64,7 +64,7 @@ type TernaryPredicate = ( value: any, index: number, collection: Collection ) =>
* @param collection - input collection
* @returns boolean indicating whether an element in a collection passes a test
*/
type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; // tslint-disable-line max-line-length
type Predicate<T> = NullaryPredicate | UnaryPredicate<T> | BinaryPredicate<T> | TernaryPredicate<T>; // tslint-disable-line max-line-length

/**
* Function invoked for each collection element until test condition is true.
Expand All @@ -76,15 +76,15 @@ type Nullary = () => void;
*
* @param value - collection value
*/
type Unary = ( value: any ) => void;
type Unary<T> = ( value: T ) => void;

/**
* Function invoked for each collection element until test condition is true.
*
* @param value - collection value
* @param index - collection index
*/
type Binary = ( value: any, index: number ) => void;
type Binary<T> = ( value: T, index: number ) => void;

/**
* Function invoked for each collection element until test condition is true.
Expand All @@ -93,7 +93,7 @@ type Binary = ( value: any, index: number ) => void;
* @param index - collection index
* @param collection - input collection
*/
type Ternary = ( value: any, index: number, collection: Collection ) => void;
type Ternary<T> = ( value: T, index: number, collection: Collection<T> ) => void; // tslint-disable-line max-line-length

/**
* Function invoked for each collection element until test condition is true.
Expand All @@ -102,7 +102,7 @@ type Ternary = ( value: any, index: number, collection: Collection ) => void;
* @param index - collection index
* @param collection - input collection
*/
type Callback = Nullary | Unary | Binary | Ternary;
type Callback<T> = Nullary | Unary<T> | Binary<T> | Ternary<T>;

/**
* Until a test condition is true, invokes a function once for each element in a collection, iterating from right to left.
Expand Down Expand Up @@ -136,7 +136,7 @@ type Callback = Nullary | Unary | Binary | Ternary;
*
* untilEachRight( arr, predicate, log );
*/
declare function untilEachRight( collection: Collection, predicate: Predicate, fcn: Callback, thisArg?: any ): Collection; // tslint-disable-line max-line-length
declare function untilEachRight<T = any>( collection: Collection<T>, predicate: Predicate<T>, fcn: Callback<T>, thisArg?: any ): Collection<T>; // tslint-disable-line max-line-length


// EXPORTS //
Expand Down
70 changes: 44 additions & 26 deletions until-each-right/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,72 @@

import untilEachRight = require( './index' );

const log = ( v: any, index: number ): void => {
console.log( `${index}: ${v}` );
};
/**
* Test function.
*
* @param v - value
* @param index - index
*/
function fcn( v: number, index: number ): void {
if ( v !== v ) {
throw new Error( 'beep' );
}
if ( index !== index ) {
throw new Error( 'beep' );
}
}

/**
* Test function.
*
* @param v - value
* @returns result
*/
function isnan( v: number ): boolean {
return ( v !== v );
}

const isNotNaN = ( v: number ): boolean => {
return ( v === v );
};

// TESTS //

// The function returns the input collection...
{
untilEachRight( [ 0, 1, 1, NaN, 2 ], isNotNaN, log ); // $ExpectType Collection
untilEachRight( [ -1, 1, 2 ], isNotNaN, log, {} ); // $ExpectType Collection
untilEachRight( [ 0, 1, 1, NaN, 2 ], isnan, fcn ); // $ExpectType Collection<number>
untilEachRight( [ -1, 1, 2 ], isnan, fcn, {} ); // $ExpectType Collection<number>
}

// The compiler throws an error if the function is provided a first argument which is not a collection...
{
untilEachRight( 2, isNotNaN, log ); // $ExpectError
untilEachRight( false, isNotNaN, log ); // $ExpectError
untilEachRight( true, isNotNaN, log ); // $ExpectError
untilEachRight( {}, isNotNaN, log ); // $ExpectError
untilEachRight( 2, isnan, fcn ); // $ExpectError
untilEachRight( false, isnan, fcn ); // $ExpectError
untilEachRight( true, isnan, fcn ); // $ExpectError
untilEachRight( {}, isnan, fcn ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not a function...
{
untilEachRight( [ 0, 1, 1, NaN, 2 ], 2, log ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], false, log ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], true, log ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], 'abc', log ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], {}, log ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], [], log ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], 2, fcn ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], false, fcn ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], true, fcn ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], 'abc', fcn ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], {}, fcn ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], [], fcn ); // $ExpectError
}

// The compiler throws an error if the function is provided a third argument which is not a function...
{
untilEachRight( [ 0, 1, 1, NaN, 2 ], isNotNaN, 2 ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isNotNaN, false ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isNotNaN, true ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isNotNaN, 'abc' ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isNotNaN, {} ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isNotNaN, [] ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isnan, 2 ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isnan, false ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isnan, true ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isnan, 'abc' ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isnan, {} ); // $ExpectError
untilEachRight( [ 0, 1, 1, NaN, 2 ], isnan, [] ); // $ExpectError
}

// The compiler throws an error if the function is provided an invalid number of arguments...
{
untilEachRight(); // $ExpectError
untilEachRight( [ 1, 2, 3 ] ); // $ExpectError
untilEachRight( [ 1, 2, 3 ], isNotNaN ); // $ExpectError
untilEachRight( [ 1, 2, 3 ], isNotNaN, log, {}, 3 ); // $ExpectError
untilEachRight( [ 1, 2, 3 ], isnan ); // $ExpectError
untilEachRight( [ 1, 2, 3 ], isnan, fcn, {}, 3 ); // $ExpectError
}
18 changes: 9 additions & 9 deletions until-each/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type NullaryPredicate = () => boolean;
* @param value - collection value
* @returns boolean indicating whether an element in a collection passes a test
*/
type UnaryPredicate = ( value: any ) => boolean;
type UnaryPredicate<T> = ( value: T ) => boolean;

/**
* Checks whether an element in a collection passes a test.
Expand All @@ -44,7 +44,7 @@ type UnaryPredicate = ( value: any ) => boolean;
* @param index - collection index
* @returns boolean indicating whether an element in a collection passes a test
*/
type BinaryPredicate = ( value: any, index: number ) => boolean;
type BinaryPredicate<T> = ( value: T, index: number ) => boolean;

/**
* Checks whether an element in a collection passes a test.
Expand All @@ -54,7 +54,7 @@ type BinaryPredicate = ( value: any, index: number ) => boolean;
* @param collection - input collection
* @returns boolean indicating whether an element in a collection passes a test
*/
type TernaryPredicate = ( value: any, index: number, collection: Collection ) => boolean; // tslint-disable-line max-line-length
type TernaryPredicate<T> = ( value: T, index: number, collection: Collection<T> ) => boolean; // tslint-disable-line max-line-length

/**
* Checks whether an element in a collection passes a test.
Expand All @@ -64,7 +64,7 @@ type TernaryPredicate = ( value: any, index: number, collection: Collection ) =>
* @param collection - input collection
* @returns boolean indicating whether an element in a collection passes a test
*/
type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; // tslint-disable-line max-line-length
type Predicate<T> = NullaryPredicate | UnaryPredicate<T> | BinaryPredicate<T> | TernaryPredicate<T>; // tslint-disable-line max-line-length

/**
* Function invoked for each collection element until test condition is true.
Expand All @@ -76,15 +76,15 @@ type Nullary = () => void;
*
* @param value - collection value
*/
type Unary = ( value: any ) => void;
type Unary<T> = ( value: T ) => void;

/**
* Function invoked for each collection element until test condition is true.
*
* @param value - collection value
* @param index - collection index
*/
type Binary = ( value: any, index: number ) => void;
type Binary<T> = ( value: T, index: number ) => void;

/**
* Function invoked for each collection element until test condition is true.
Expand All @@ -93,7 +93,7 @@ type Binary = ( value: any, index: number ) => void;
* @param index - collection index
* @param collection - input collection
*/
type Ternary = ( value: any, index: number, collection: Collection ) => void;
type Ternary<T> = ( value: T, index: number, collection: Collection<T> ) => void; // tslint-disable-line max-line-length

/**
* Function invoked for each collection element until test condition is true.
Expand All @@ -102,7 +102,7 @@ type Ternary = ( value: any, index: number, collection: Collection ) => void;
* @param index - collection index
* @param collection - input collection
*/
type Callback = Nullary | Unary | Binary | Ternary;
type Callback<T> = Nullary | Unary<T> | Binary<T> | Ternary<T>;

/**
* Until a test condition is true, invokes a function once for each element in a collection.
Expand Down Expand Up @@ -134,7 +134,7 @@ type Callback = Nullary | Unary | Binary | Ternary;
*
* untilEach( arr, predicate, log );
*/
declare function untilEach( collection: Collection, predicate: Predicate, fcn: Callback, thisArg?: any ): Collection; // tslint-disable-line max-line-length
declare function untilEach<T = any>( collection: Collection<T>, predicate: Predicate<T>, fcn: Callback<T>, thisArg?: any ): Collection<T>; // tslint-disable-line max-line-length


// EXPORTS //
Expand Down
70 changes: 44 additions & 26 deletions until-each/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,72 @@

import untilEach = require( './index' );

const log = ( v: any, index: number ): void => {
console.log( `${index}: ${v}` );
};
/**
* Test function.
*
* @param v - value
* @param index - index
*/
function fcn( v: number, index: number ): void {
if ( v !== v ) {
throw new Error( 'beep' );
}
if ( index !== index ) {
throw new Error( 'beep' );
}
}

/**
* Test function.
*
* @param v - value
* @returns result
*/
function isnan( v: number ): boolean {
return ( v !== v );
}

const isNotNaN = ( v: number ): boolean => {
return ( v === v );
};

// TESTS //

// The function returns the input collection...
{
untilEach( [ 0, 1, 1, NaN, 2 ], isNotNaN, log ); // $ExpectType Collection
untilEach( [ -1, 1, 2 ], isNotNaN, log, {} ); // $ExpectType Collection
untilEach( [ 0, 1, 1, NaN, 2 ], isnan, fcn ); // $ExpectType Collection<number>
untilEach( [ -1, 1, 2 ], isnan, fcn, {} ); // $ExpectType Collection<number>
}

// The compiler throws an error if the function is provided a first argument which is not a collection...
{
untilEach( 2, isNotNaN, log ); // $ExpectError
untilEach( false, isNotNaN, log ); // $ExpectError
untilEach( true, isNotNaN, log ); // $ExpectError
untilEach( {}, isNotNaN, log ); // $ExpectError
untilEach( 2, isnan, fcn ); // $ExpectError
untilEach( false, isnan, fcn ); // $ExpectError
untilEach( true, isnan, fcn ); // $ExpectError
untilEach( {}, isnan, fcn ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not a function...
{
untilEach( [ 0, 1, 1, NaN, 2 ], 2, log ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], false, log ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], true, log ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], 'abc', log ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], {}, log ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], [], log ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], 2, fcn ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], false, fcn ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], true, fcn ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], 'abc', fcn ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], {}, fcn ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], [], fcn ); // $ExpectError
}

// The compiler throws an error if the function is provided a third argument which is not a function...
{
untilEach( [ 0, 1, 1, NaN, 2 ], isNotNaN, 2 ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isNotNaN, false ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isNotNaN, true ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isNotNaN, 'abc' ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isNotNaN, {} ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isNotNaN, [] ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isnan, 2 ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isnan, false ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isnan, true ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isnan, 'abc' ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isnan, {} ); // $ExpectError
untilEach( [ 0, 1, 1, NaN, 2 ], isnan, [] ); // $ExpectError
}

// The compiler throws an error if the function is provided an invalid number of arguments...
{
untilEach(); // $ExpectError
untilEach( [ 1, 2, 3 ] ); // $ExpectError
untilEach( [ 1, 2, 3 ], isNotNaN ); // $ExpectError
untilEach( [ 1, 2, 3 ], isNotNaN, log, {}, 3 ); // $ExpectError
untilEach( [ 1, 2, 3 ], isnan ); // $ExpectError
untilEach( [ 1, 2, 3 ], isnan, fcn, {}, 3 ); // $ExpectError
}
21 changes: 17 additions & 4 deletions while-each-right/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,31 @@

import whileEachRight = require( './index' );

const fcn = ( v: number, index: number ): void => {
/**
* Test function.
*
* @param v - value
* @param index - index
*/
function fcn( v: number, index: number ): void {
if ( v !== v ) {
throw new Error( 'beep' );
}
if ( index !== index ) {
throw new Error( 'beep' );
}
};
}

const isnan = ( v: number ): boolean => {
/**
* Test function.
*
* @param v - value
* @returns result
*/
function isnan( v: number ): boolean {
return ( v !== v );
};
}


// TESTS //

Expand Down
Loading

0 comments on commit fe36ece

Please sign in to comment.