UNPKG

pragmatic-fp-ts

Version:

Opinionated functional programming library with easy use in mind

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