Skip to content

Latest commit

 

History

History
56 lines (52 loc) · 2.07 KB

File metadata and controls

56 lines (52 loc) · 2.07 KB

Roadmap

  • 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()
  • Add a custom matcher protocol data structures could implement to make them matchable.
  • (Maybe) add an iterator protocol to P.array to be usable as a variadic tuple pattern. Example of using P.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() and select('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 select API 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 when if the predicate is a type guard.