| 396 | * @since 4.0.0 |
| 397 | */ |
| 398 | export 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. |