UNPKG

iter-tools

Version:
99 lines (80 loc) 2.65 kB
var _regeneratorRuntime = require("@babel/runtime/regenerator"); var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator"); var _require = require('../../internal/async-iterable.js'), asyncIterableCurry = _require.asyncIterableCurry; var _require2 = require('../$peekerate/async-peekerate.js'), __asyncPeekerate = _require2.__asyncPeekerate; function __asyncFindBestOr(_x, _x2, _x3) { return _asyncFindBestOr.apply(this, arguments); } function _asyncFindBestOr() { _asyncFindBestOr = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(iterable, notFoundValue, comparer) { var mapper, peekr, best, bestValue, candidate, candidateValue, _args = arguments; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: mapper = _args.length > 3 && _args[3] !== undefined ? _args[3] : function (value) { return value; }; _context.next = 3; return __asyncPeekerate(iterable); case 3: peekr = _context.sent; if (!peekr.done) { _context.next = 8; break; } return _context.abrupt("return", notFoundValue); case 8: best = peekr.value; _context.next = 11; return mapper(best, peekr.index); case 11: bestValue = _context.sent; _context.next = 14; return peekr.advance(); case 14: if (peekr.done) { _context.next = 24; break; } candidate = peekr.value; _context.next = 18; return mapper(candidate, peekr.index); case 18: candidateValue = _context.sent; if (comparer(bestValue, candidateValue)) { best = candidate; bestValue = candidateValue; } _context.next = 22; return peekr.advance(); case 22: _context.next = 14; break; case 24: return _context.abrupt("return", best); case 25: case "end": return _context.stop(); } } }, _callee); })); return _asyncFindBestOr.apply(this, arguments); } exports.__asyncFindBestOr = __asyncFindBestOr; var asyncFindBestOr = asyncIterableCurry(__asyncFindBestOr, { reduces: true, minArgs: 2, maxArgs: 3, growRight: true }); exports.asyncFindBestOr = asyncFindBestOr;