import { Matcher, } from './Matcher' import { MatchResult, MatchResultAny, Matched, isMatched, } from './MatchResult' export type AndMatcherResult = MatchResult<{ and: [Matched, Matched] }> /** * Match if every matcher matches */ export class AndMatcher implements Matcher, P1 & P2> { constructor(private readonly matchers: [Matcher, Matcher]) { this.match = this.match.bind(this) } match(params: P1 & P2): AndMatcherResult { const [matcher1, matcher2] = this.matchers const result1 = matcher1.match(params) if (isMatched(result1)) { const result2 = matcher2.match(params) if (isMatched(result2)) { return { matched: true, result: { and: [result1, result2], }, } } } return { matched: false, } } }