tiny-types
Version:
A tiny library that brings Tiny Types to JavaScript and TypeScript
16 lines (13 loc) • 554 B
text/typescript
import { PatternMatcher } from './PatternMatcher';
import { MatchesIdentical } from './rules';
/**
* @access private
*/
export class IdentityMatcher<Input_Type, Output_Type> extends PatternMatcher<Input_Type, Input_Type, Input_Type, Output_Type> {
when(pattern: Input_Type, transformation: (v: Input_Type) => Output_Type): PatternMatcher<Input_Type, Input_Type, Input_Type, Output_Type> {
return new IdentityMatcher(
this.value,
this.rules.concat(new MatchesIdentical(pattern, transformation)),
);
}
}