MCPcopy Index your code
hub / github.com/Effect-TS/effect / discriminators

Function discriminators

packages/effect/src/internal/matcher.ts:398–427  ·  view source on GitHub ↗
(field: D)

Source from the content-addressed store, hash-verified

396
397/** @internal */
398export const discriminators = <D extends string>(field: D) =>
399<
400 R,
401 Ret,
402 P extends
403 & {
404 readonly [Tag in Types.Tags<D, R> & string]?:
405 | ((_: Extract<R, Record<D, Tag>>) => Ret)
406 | undefined
407 }
408 & { readonly [Tag in Exclude<keyof P, Types.Tags<D, R>>]: never }
409>(
410 fields: P
411) => {
412 const predicate = makeWhen(
413 (arg: any) => arg != null && arg[field] in fields,
414 (data: any) => (fields as any)[data[field]](data)
415 )
416
417 return <I, F, A, Pr>(
418 self: Matcher<I, F, R, A, Pr, Ret>
419 ): Matcher<
420 I,
421 Types.AddWithout<F, Extract<R, Record<D, keyof P>>>,
422 Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, keyof P>>>>,
423 A | ReturnType<P[keyof P] & {}>,
424 Pr,
425 Ret
426 > => (self as any).add(predicate)
427}
428
429/** @internal */
430export const discriminatorsExhaustive: <D extends string>(

Callers 2

discriminatorsExhaustiveFunction · 0.85
matcher.tsFile · 0.85

Calls 2

makeWhenFunction · 0.85
addMethod · 0.65

Tested by

no test coverage detected