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

Function swap

packages/effect/src/internal/stm/tRandom.ts:52–68  ·  view source on GitHub ↗
(buffer: TArray.TArray<A>, index1: number, index2: number)

Source from the content-addressed store, hash-verified

50 nextIntBounded: (n: number) => STM.STM<number>
51): STM.STM<Array<A>> => {
52 const swap = (buffer: TArray.TArray<A>, index1: number, index2: number): STM.STM<void> =>
53 pipe(
54 buffer,
55 tArray.get(index1),
56 core.flatMap((tmp) =>
57 pipe(
58 buffer,
59 tArray.updateSTM(index1, () => pipe(buffer, tArray.get(index2))),
60 core.zipRight(
61 pipe(
62 buffer,
63 tArray.update(index2, () => tmp)
64 )
65 )
66 )
67 )
68 )
69 return pipe(
70 tArray.fromIterable(iterable),
71 core.flatMap((buffer) => {

Callers 1

shuffleWithFunction · 0.70

Calls 3

getMethod · 0.65
updateMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…