Codibre/fluent-iterable

View on GitHub
src/recipes/augment-iterable-recipe.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { AnyIterable, itClone } from 'augmentative-iterable';
import { AnyMapper, orderAssured } from '../types-internal';
import { prepare } from '../types-internal/prepare';

export function augmentIterableRecipe(
  augmentIterable: Function,
  clone?: boolean,
) {
  if (clone) {
    return function <T>(
      this: AnyIterable<T>,
      action: AnyMapper<T>,
    ): AnyIterable<T> {
      return augmentIterable(
        (this as any)[orderAssured] ? itClone(this) : this,
        prepare(action),
        true,
      );
    };
  }

  return function <T>(
    this: AnyIterable<T>,
    action: AnyMapper<T>,
  ): AnyIterable<T> {
    return augmentIterable(this, prepare(action), true);
  };
}