UNPKG

pragmatic-fp-ts

Version:

Opinionated functional programming library with easy use in mind

16 lines (15 loc) 549 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.find = void 0; const main_1 = require("./main"); function find(condition, coll) { if (arguments.length === 1) { return (theColl) => find(condition, theColl); } const toCollection = (a) => (0, main_1.isNil)(a) ? null : a instanceof Array ? a : Object.values(a); return (0, main_1.maybe)((0, main_1.getValue)(coll)) .bind(toCollection) .bind((c) => c.find(condition) || null) .getValueOr(null); } exports.find = find;