MCPcopy
hub / github.com/Effect-TS/effect / choice

Function choice

packages/effect/src/internal/defaultServices.ts:137–147  ·  view source on GitHub ↗
(
  elements: Self
)

Source from the content-addressed store, hash-verified

135
136/** @internal */
137export const choice = <Self extends Iterable<unknown>>(
138 elements: Self
139) => {
140 const array = Array.fromIterable(elements)
141 return core.map(
142 array.length === 0
143 ? core.fail(new core.NoSuchElementException("Cannot select a random element from an empty array"))
144 : randomWith((random) => random.nextIntBetween(0, array.length)),
145 (i) => array[i]
146 ) as any
147}
148
149// circular with Tracer
150

Callers

nothing calls this directly

Calls 4

randomWithFunction · 0.85
mapMethod · 0.65
failMethod · 0.65
nextIntBetweenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…