Function: find()
Returns an iterable containing the first value of iterable
for which fn
returns a truthy value. Otherwise, returns an empty iterable.
Like Array.prototype.find
, but for iterables.
Example
import { find, or, pipe } from 'lfi'
console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
find(word => word.includes(`s`)),
or(() => `not found!`),
),
)
//=> sloth
console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
find(word => word.includes(`x`)),
or(() => `not found!`),
),
)
//=> not found!
Since
v0.0.1
Call Signature
find<
Value
>(fn
): (iterable
) =>Optional
<Value
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
Returns
Function
Parameters
iterable
Iterable
<Value
, any
, any
>
Returns
Optional
<Value
>
Defined in
Call Signature
find<
Value
>(fn
,iterable
):Optional
<Value
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
iterable
Iterable
<Value
, any
, any
>
Returns
Optional
<Value
>