// ets_tracing: off
import type { Refinement } from "../../../../Function/index.js"
import * as O from "../../../../Option/index.js"
import type * as Chunk from "../core.js"
import { concreteId } from "../definition.js"
/**
* Returns the first element that satisfies the predicate.
*/
export function find_(
self: Chunk.Chunk,
f: Refinement
): O.Option
export function find_(self: Chunk.Chunk, f: (a: A) => boolean): O.Option
export function find_(self: Chunk.Chunk, f: (a: A) => boolean): O.Option {
const iterator = concreteId(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 O.some(a)
}
i++
}
}
return O.none
}
/**
* Returns the first element that satisfies the predicate.
*
* @ets_data_first find_
*/
export function find(
f: Refinement
): (self: Chunk.Chunk) => O.Option
export function find(f: (a: A) => boolean): (self: Chunk.Chunk) => O.Option
export function find(f: (a: A) => boolean): (self: Chunk.Chunk) => O.Option {
return (self) => find_(self, f)
}