Skip to content

Commit

Permalink
docs(TypeDoc): Count & length
Browse files Browse the repository at this point in the history
Add documentation for count and length functions.
  • Loading branch information
danielrbradley committed Jul 20, 2018
1 parent 1948949 commit 3fcf761
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,18 @@ export function init<T>(
return target
}

/**
* Returns the number of items in the array.
* @param source The input collection.
*/
export function length<T>(source: T[]): number {
return source.length
}

/**
* Returns the number of items in the array.
* @param source The input collection.
*/
export function count<T>(source: T[]): number {
return source.length
}
Expand Down
8 changes: 8 additions & 0 deletions src/iterables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,18 @@ export function take<T>(a: any, b?: any): any {
return partial ? exec : exec(a)
}

/**
* Returns the number of items in the collection.
* @param source The input collection.
*/
export function length<T>(source: Iterable<T>): number {
return count(source)
}

/**
* Returns the number of items in the collection.
* @param source The input collection.
*/
export function count<T>(source: Iterable<T>): number {
let length = 0
for (const _ of source) {
Expand Down
4 changes: 4 additions & 0 deletions src/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ export function containsKey<Key, T>(a: any, b?: any): any {
return partial ? exec : exec(a)
}

/**
* Returns the number of items in the collection.
* @param source The input collection.
*/
export function count<Key, T>(source: Map<Key, T>): number {
return source.size
}
4 changes: 4 additions & 0 deletions src/sets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ export function find<T>(a: any, b?: any): any {
return partial ? exec : exec(a)
}

/**
* Returns the number of items in the collection.
* @param source The input collection.
*/
export function count<T>(source: Set<T>): number {
return source.size
}

0 comments on commit 3fcf761

Please sign in to comment.