• P.map(keyPattern, valuePattern) takes a subpattern to match against the key, a subpattern to match against the value and returns a pattern that matches on maps where all elements inside the map match those two subpatterns.

    Read P.map documentation on GitHub

    Type Parameters

    • input

    Returns Chainable<MapP<input, unknown, unknown>>

    Example

    match(value)
    .with({ users: P.map(P.map(P.string, P.number)) }, (map) => `map's type is Map<string, number>`)
  • Type Parameters

    • input
    • const pkey extends readonly [] | readonly [unknown, unknown] | readonly [unknown, unknown] | {
          [k: string]: unknown;
      } | Primitives | UnknownMatcher | readonly UnknownPattern[] | readonly [UnknownPattern, UnknownPattern] | readonly [UnknownPattern, UnknownPattern] | PatternMatcher<WithDefault<UnwrapMapKey<input>, unknown>> | {
          readonly [k in string | number | symbol]?: Pattern<Readonly<MergeUnion<Exclude<WithDefault<UnwrapMapKey<input>, unknown>, (readonly any[] | Primitives | Map<any, any> | Set<any>)>>>[k]>
      }
    • const pvalue extends readonly [] | readonly [unknown, unknown] | readonly [unknown, unknown] | {
          [k: string]: unknown;
      } | Primitives | UnknownMatcher | readonly UnknownPattern[] | readonly [UnknownPattern, UnknownPattern] | readonly [UnknownPattern, UnknownPattern] | PatternMatcher<WithDefault<UnwrapMapValue<input>, unknown>> | {
          readonly [k in string | number | symbol]?: Pattern<Readonly<MergeUnion<Exclude<WithDefault<UnwrapMapValue<input>, unknown>, (readonly any[] | Primitives | Map<any, any> | Set<any>)>>>[k]>
      }

    Parameters

    Returns Chainable<MapP<input, pkey, pvalue>>