MCPcopy Create free account
hub / github.com/Effect-TS/effect / choice

Function choice

packages/effect/src/unstable/cli/Primitive.ts:398–410  ·  view source on GitHub ↗
(
  choices: ReadonlyArray<readonly [string, A]>
)

Source from the content-addressed store, hash-verified

396 * @since 4.0.0
397 */
398export const choice = <A>(
399 choices: ReadonlyArray<readonly [string, A]>
400): Primitive<A> => {
401 const choiceMap = new Map(choices)
402 const validChoices = choices.map(([key]) => format(key)).join(" | ")
403 const primitive = makePrimitive("Choice", (value) => {
404 if (choiceMap.has(value)) {
405 return Effect.succeed(choiceMap.get(value)!)
406 }
407 return Effect.fail(validChoices)
408 })
409 return Object.assign(primitive, { choiceKeys: choices.map(([key]) => key) })
410}
411
412/**
413 * Specifies the type of path validation to perform.

Callers

nothing calls this directly

Calls 9

formatFunction · 0.90
joinMethod · 0.80
assignMethod · 0.80
makePrimitiveFunction · 0.70
getMethod · 0.65
mapMethod · 0.45
hasMethod · 0.45
succeedMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected