<A>(elements: Iterable<A>): Effect.Effect<Array<A>>Uses the pseudo-random number generator to shuffle the specified iterable.
When to use
Use to randomly reorder an iterable using the active Random service.
Example (Shuffling values)
import { Effect, Random } from "effect"
const program = Effect.gen(function*() {
const values = yield* Random.shuffle([1, 2, 3, 4, 5])
console.log(values)
})export const const shuffle: <A>(
elements: Iterable<A>
) => Effect.Effect<Array<A>>
Uses the pseudo-random number generator to shuffle the specified iterable.
When to use
Use to randomly reorder an iterable using the active Random service.
Example (Shuffling values)
import { Effect, Random } from "effect"
const program = Effect.gen(function*() {
const values = yield* Random.shuffle([1, 2, 3, 4, 5])
console.log(values)
})
shuffle = <function (type parameter) A in <A>(elements: Iterable<A>): Effect.Effect<Array<A>>A>(elements: Iterable<A>elements: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(elements: Iterable<A>): Effect.Effect<Array<A>>A>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Array<T>Array<function (type parameter) A in <A>(elements: Iterable<A>): Effect.Effect<Array<A>>A>> =>
const randomWith: <A>(
f: (random: (typeof Random)["Service"]) => A
) => Effect.Effect<A>
randomWith((r: Context.Reference<{
nextIntUnsafe(): number
nextDoubleUnsafe(): number
}>
(parameter) r: {
nextIntUnsafe: () => number;
nextDoubleUnsafe: () => number;
}
r) => {
const const buffer: A[]buffer = var Array: ArrayConstructorArray.ArrayConstructor.from<A>(iterable: Iterable<A> | ArrayLike<A>): A[] (+3 overloads)Creates an array from an iterable object.
from(elements: Iterable<A>elements)
for (let let i: numberi = const buffer: A[]buffer.Array<A>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length - 1; let i: numberi >= 1; let i: numberi = let i: numberi - 1) {
const const index: numberindex = var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.min(...values: number[]): numberReturns the smaller of a set of supplied numeric expressions.
min(let i: numberi, var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.floor(x: number): numberReturns the greatest integer less than or equal to its numeric argument.
floor(r: Context.Reference<{
nextIntUnsafe(): number
nextDoubleUnsafe(): number
}>
(parameter) r: {
nextIntUnsafe: () => number;
nextDoubleUnsafe: () => number;
}
r.nextDoubleUnsafe() * (let i: numberi + 1)))
const const value: NonNullable<A>value = const buffer: A[]buffer[let i: numberi]!
const buffer: A[]buffer[let i: numberi] = const buffer: A[]buffer[const index: numberindex]!
const buffer: A[]buffer[const index: numberindex] = const value: NonNullable<A>value
}
return const buffer: A[]buffer
})