Hyperlinkv0.8.0-beta.28

Chunk

Chunk.replaceconsteffect/Chunk.ts:2476
<B>(i: number, b: B): <A>(self: Chunk<A>) => O.Option<Chunk<B | A>>
<A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>

Changes the element at the specified index safely, creating a new Chunk, or returns None if the index is out of bounds.

Example (Replacing an element)

import { Chunk } from "effect"

const chunk = Chunk.make("a", "b", "c", "d")
const result = Chunk.replace(chunk, 1, "X")
console.log(result) // Option.some(Chunk.make("a", "X", "c", "d"))

// Index out of bounds returns None
const outOfBounds = chunk.pipe(Chunk.replace(10, "Y"))
console.log(outOfBounds) // Option.none()

// Negative index returns None
const negative = chunk.pipe(Chunk.replace(-1, "Z"))
console.log(negative) // Option.none()
elements
Source effect/Chunk.ts:24764 lines
export const replace: {
  <B>(i: number, b: B): <A>(self: Chunk<A>) => O.Option<Chunk<B | A>>
  <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>>
} = dual(3, <A, B>(self: Chunk<A>, i: number, b: B): O.Option<Chunk<B | A>> => modify(self, i, () => b))