import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" /** * Returns the first element that satisfies the predicate. * * @tsplus static Chunk.Aspects find * @tsplus pipeable Chunk find */ export function find(f: Refinement): (self: Chunk) => Maybe export function find(f: Predicate): (self: Chunk) => Maybe export function find(f: Predicate) { return (self: Chunk): Maybe => { const iterator = concreteChunkId(self)._arrayLikeIterator() let next while ((next = iterator.next()) && !next.done) { const array = next.value const len = array.length let i = 0 while (i < len) { const a = array[i]! if (f(a)) { return Maybe.some(a) } i++ } } return Maybe.none } }