type Condition < T > = T | ( ( val : T ) => boolean ) ; function predicate < T > ( val , cond ) { if ( cond instanceof Function ) { return cond ( val ) ; } else { return val === cond ; } } export function match < V , T > ( val , matches , fallback ) { for ( const [ p , f ] of matches ) { if ( predicate ( val , p ) ) { return f ( ) ; } } return fallback ( ) ; } export function isDigit ( c ) { return /^[0-9]$/ . test ( c ) ; } export function isAlphabet ( c ) { return /^[a-zA-Z]$/ . test ( c ) ; } export function isAlphanumeric ( c ) { return isDigit ( c ) || isAlphabet ( c ) ; } export function unescape ( str ) { return str . replace ( /\\n/g , '\n' ) . replace ( /\\r/g , '\r' ) . replace ( /\\t/g , '\t' ) . replace ( /\\\\/g , '\\' ) . replace ( /\\'/g , "'" ) . replace ( /\\"/g , '"' ) ; } export function orStr ( words ) { const last = words . slice ( - 1 ) [ 0 ] ; const rests = words . slice ( 0 , - 1 ) . join ( ', ' ) ; return rests ? `${ rests } or ${ last }` : last ; } export type Arity1 < T , U = T > = ( x : T ) => U ; export class Compose < T , U > { constructor ( public f ) { } static then < T , U > ( f ) { return new Compose ( f ) ; } then < V > ( g ) { return new Compose ( ( x ) => g ( this . f ( x ) ) ) ; } }