pragmatic-fp-ts
Version:
Opinionated functional programming library with easy use in mind
13 lines (12 loc) • 368 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.nth = void 0;
const main_1 = require("./main");
function nth(n, coll) {
if (arguments.length === 1)
return (_coll) => nth(n, _coll);
const l = coll.length;
const idx = n < 0 ? (0, main_1.mod)(l, n) : n >= l ? l - 1 : n;
return coll[idx];
}
exports.nth = nth;