MCPcopy
hub / github.com/gvergnaud/ts-pattern / select

Function select

src/patterns.ts:696–732  ·  view source on GitHub ↗
(
  ...args: [keyOrPattern?: unknown | string, pattern?: unknown]
)

Source from the content-addressed store, hash-verified

694 pattern: pattern
695): Chainable<SelectP<k, input, pattern>, 'select' | 'or' | 'and'>;
696export function select(
697 ...args: [keyOrPattern?: unknown | string, pattern?: unknown]
698): Chainable<SelectP<string>, 'select' | 'or' | 'and'> {
699 const key: string | undefined =
700 typeof args[0] === 'string' ? args[0] : undefined;
701 const pattern: unknown =
702 args.length === 2
703 ? args[1]
704 : typeof args[0] === 'string'
705 ? undefined
706 : args[0];
707 return chainable({
708 [matcher]() {
709 return {
710 match: (value) => {
711 let selections: Record<string, unknown> = {
712 [key ?? symbols.anonymousSelectKey]: value,
713 };
714 const selector = (key: string, value: any) => {
715 selections[key] = value;
716 };
717 return {
718 matched:
719 pattern === undefined
720 ? true
721 : matchPattern(pattern, value, selector),
722 selections: selections,
723 };
724 },
725 getSelectionKeys: () =>
726 [key ?? symbols.anonymousSelectKey].concat(
727 pattern === undefined ? [] : getSelectionKeys(pattern)
728 ),
729 };
730 },
731 });
732}
733
734function isUnknown(x: unknown): x is unknown {
735 return true;

Callers 3

chainableFunction · 0.85
arrayChainableFunction · 0.85
matchPatternFunction · 0.85

Calls 1

chainableFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…