- chainable methods
- string
-
P.string.includes('str') -
P.string.startsWith('str') -
P.string.endsWith('str') -
P.string.regex('[a-z]+')
-
- numbers
-
P.number.between(1, 10) -
P.number.lt(12) -
P.number.gt(12) -
P.number.gte(12) -
P.number.lte(12) -
P.number.int(12) -
P.number.finite -
P.number.positive -
P.number.negative
-
- all
-
P.number.optional -
P.string.optional -
P.number.select() -
P.string.select() -
P.number.optional.select() -
P.string.optional.select()
-
- string
- Add a custom matcher protocol data structures could implement to make them matchable.
- (Maybe) add an iterator protocol to
P.arrayto be usable as a variadic tuple pattern. Example of usingP.array:
const reverse = <T>(xs: T[]): T[] => {
return match<T[], T[]>(xs)
.with([P.any, ...P.array()], ([x, ...xs]) => [...reverse(xs), x])
.otherwise(() => []);
};
match(xs)
.with([P.any, ...P.array()], (xs: [unknown, ...unknown[]]) => [])
.with([42, ...P.array(P.number), '!'], (xs: [42, ...number[], '!']) => [])
.with(
[...P.array(P.number), ...P.array(P.string)],
(xs: [...number[], ...string[]]) => []
)
.otherwise(() => []);- update
select()andselect('name')to accept a pattern the selected value should match. - add a
union(...patterns)pattern. - When not provided, maybe compute the output type from all branches
- maybe add a lightweight
selectAPI for single values - add support matching against several patterns in a single
.with()clause. - Find a way to enforce exhaustive pattern matching
- Several pattern/when clauses if necessary, with refined type inference from one to the other
- Find a way to make the full type inference work
- Add an operator to select a part of the data structure
- Add
not(value)in patterns. - Narrow down to type of value in
whenif the predicate is a type guard.