UNPKG

@thi.ng/transducers

Version:

Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations

12 lines (11 loc) 365 B
import { isIterable } from "@thi.ng/checks/is-iterable"; import { comp } from "./comp.js"; import { filter } from "./filter.js"; import { iterator1 } from "./iterator.js"; import { take } from "./take.js"; function matchFirst(pred, src) { return isIterable(src) ? [...iterator1(matchFirst(pred), src)][0] : comp(filter(pred), take(1)); } export { matchFirst };