import {ArgumentError} from '../argument-error'; import {BasePredicate, testSymbol} from './base-predicate'; import {Ow} from '../..'; /** * @hidden */ export class AnyPredicate implements BasePredicate { constructor( private readonly predicates: BasePredicate[] ) {} // tslint:disable completed-docs [testSymbol](value: T, main: Ow, label?: string) { const errors = [ 'Any predicate failed with the following errors:' ]; for (const predicate of this.predicates) { try { main(value, label as string, predicate); return; } catch (err) { errors.push(`- ${err.message}`); } } throw new ArgumentError(errors.join('\n'), main); } }