Hyperlinkv0.8.0-beta.28

Chunk

Chunk.findLastconsteffect/Chunk.ts:2693
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (
  self: Chunk<A>
) => Option<B>
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>
<A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>
<A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>

Finds the last element for which a predicate holds.

Example (Finding the last matching element)

import { Chunk, Option } from "effect"

const chunk = Chunk.make(1, 2, 3, 4, 5)
const result = Chunk.findLast(chunk, (n) => n < 4)
console.log(Option.isSome(result)) // true
console.log(Option.getOrElse(result, () => 0)) // 3

// No match found
const notFound = Chunk.findLast(chunk, (n) => n > 10)
console.log(Option.isNone(notFound)) // true

// Find last even number
const lastEven = Chunk.findLast(chunk, (n) => n % 2 === 0)
console.log(Option.getOrElse(lastEven, () => 0)) // 4
elements
Source effect/Chunk.ts:26936 lines
export const findLast: {
  <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Option<B>
  <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>
  <A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>
  <A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>
} = RA.findLast