import { Limiter } from './limiter'; import { Scope } from './scope'; export type OperatorActionFunction = (items: T[], limiter: Limiter) => T[]; export abstract class Operator { constructor(public name: string) {} abstract action(items: T[], limiter: Limiter): T[]; } export function applyOperators(items: T[], operators: Array|Operator>, limiter: Limiter): T[] { let results: T[] = [...items]; operators.forEach(operator => { if (operator instanceof Scope) { results = operator.action(results); } else { results = operator.action(results, limiter); } }); return results; }