All files / iterable/src isEmpty.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                                  8x 8x 4x   4x    
/**
 * Checks if an {@link Iterable} contains any element.
 *
 * @remarks
 * This function will consume the first element
 *
 * @example
 * ```ts
 * const iterable = [];
 * const result = isEmtpy(iterable);
 * console.log(result); // true
 * ```
 *
 * @typeParam T - the {@link Iterable} value type
 * @param iterable - the {@link Iterable} to check
 * @returns `true` if the {@link Iterable} is empty, otherwise `false`
 */
export const isEmpty = <T>(iterable: Iterable<T>): boolean => {
  for (const _ of iterable) {
    return false;
  }
  return true;
};