Hyperlinkv0.8.0-beta.28

Chunk

Chunk.modifyconsteffect/Chunk.ts:2442
<A, B>(i: number, f: (a: A) => B): (
  self: Chunk<A>
) => O.Option<Chunk<A | B>>
<A, B>(self: Chunk<A>, i: number, f: (a: A) => B): O.Option<Chunk<A | B>>

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

Example (Modifying an element)

import { Chunk } from "effect"

const chunk = Chunk.make(1, 2, 3, 4)
const result = Chunk.modify(chunk, 1, (n) => n * 10)
console.log(result) // Option.some(Chunk.make(1, 20, 3, 4))

// Index out of bounds returns None
const outOfBounds = chunk.pipe(Chunk.modify(10, (n) => n * 10))
console.log(outOfBounds) // Option.none()

// Negative index returns None
const negative = chunk.pipe(Chunk.modify(-1, (n) => n * 10))
console.log(negative) // Option.none()
elements
Source effect/Chunk.ts:24428 lines
export const modify: {
  <A, B>(i: number, f: (a: A) => B): (self: Chunk<A>) => O.Option<Chunk<A | B>>
  <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): O.Option<Chunk<A | B>>
} = dual(
  3,
  <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): O.Option<Chunk<A | B>> =>
    pipe(RA.modify(toReadonlyArray(self), i, f), O.map(fromArrayUnsafe))
)
Referenced by 1 symbols