Hyperlinkv0.8.0-beta.28

Chunk

Chunk.getconsteffect/Chunk.ts:533
(index: number): <A>(self: Chunk<A>) => Option<A>
<A>(self: Chunk<A>, index: number): Option<A>

Gets the value at an index in a Chunk safely, returning None when the index is out of bounds.

Example (Accessing elements safely)

import { Chunk } from "effect"

const chunk = Chunk.make("a", "b", "c", "d")

console.log(Chunk.get(chunk, 1)) // Option.some("b")
console.log(Chunk.get(chunk, 10)) // Option.none()
console.log(Chunk.get(chunk, -1)) // Option.none()

// Using pipe syntax
const result = chunk.pipe(Chunk.get(2))
console.log(result) // Option.some("c")
elements
Source effect/Chunk.ts:5338 lines
export const get: {
  (index: number): <A>(self: Chunk<A>) => Option<A>
  <A>(self: Chunk<A>, index: number): Option<A>
} = dual(
  2,
  <A>(self: Chunk<A>, index: number): Option<A> =>
    index < 0 || index >= self.length ? O.none() : O.some(getUnsafe(self, index))
)
Referenced by 3 symbols