Codibre/fluent-iterable

View on GitHub
src/recipes/get-partition-comparer.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { Equality } from '../types/base';

function partitionLengthComparer(size: number) {
  let i = 1;
  return function () {
    const result = i < size;
    i = result ? i + 1 : 1;
    return result;
  };
}

export function getPartitionComparer<T>(criteria: number | Equality<T>) {
  return typeof criteria === 'number'
    ? partitionLengthComparer(criteria)
    : criteria;
}