Package: effect
Module: Random
Get a random element from an iterable.
Example
import { Effect, Random } from "effect"
Effect.gen(function* () {
const randomItem = yield* Random.choice([1, 2, 3])
console.log(randomItem)
})
Signature
declare const choice: <Self extends Iterable<unknown>>(elements: Self) => Self extends NonEmptyIterable.NonEmptyIterable<infer A> ? Effect.Effect<A> : Self extends Array.NonEmptyReadonlyArray<infer A> ? Effect.Effect<A> : Self extends Iterable<infer A> ? Effect.Effect<A, Cause.NoSuchElementException> : never
Since v3.6.0