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

Function getSelectInitialIndex

packages/effect/src/cli/Prompt.ts:1271–1287  ·  view source on GitHub ↗
(choices: ReadonlyArray<SelectChoice<A>>)

Source from the content-addressed store, hash-verified

1269)
1270
1271const getSelectInitialIndex = <A>(choices: ReadonlyArray<SelectChoice<A>>): number => {
1272 let initialIndex = 0
1273 let seenSelected = -1
1274 for (let i = 0; i < choices.length; i++) {
1275 const choice = choices[i] as SelectChoice<A>
1276 if (choice.selected === true) {
1277 if (seenSelected !== -1) {
1278 throw new Error("InvalidArgumentException: only a single choice can be selected by default for Prompt.Select")
1279 }
1280 seenSelected = i
1281 }
1282 }
1283 if (seenSelected !== -1) {
1284 initialIndex = seenSelected
1285 }
1286 return initialIndex
1287}
1288
1289/**
1290 * Creates a prompt that lets the user select a single value from a list of

Callers 2

SelectFunction · 0.85
AutoCompleteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected