diff --git a/dist/partial.lenses.cjs.js b/dist/partial.lenses.cjs.js index 7a35cb15..8a533f9e 100644 --- a/dist/partial.lenses.cjs.js +++ b/dist/partial.lenses.cjs.js @@ -194,6 +194,8 @@ var unto = function unto(c) { }; var unto0 = /*#__PURE__*/unto(0); +var toTrue = /*#__PURE__*/I.always(true); + var notPartial = function complement(x) { return void 0 !== x ? !x : x; }; @@ -208,6 +210,8 @@ var expect = function expect(p, f) { }, f); }; +var freezeInDev = process.env.NODE_ENV === 'production' ? id : I.freeze; + function deepFreeze(x) { if (I.isArray(x)) { x.forEach(deepFreeze); @@ -316,19 +320,32 @@ function selectInArrayLike(xi2v, xs) { // -var Select = { - map: I.sndU, - of: function of() {}, - ap: function ap(l, r) { - return void 0 !== l ? l : r; - } +function Applicative(map, of, ap) { + if (!this) return freezeInDev(new Applicative(map, of, ap)); + this.map = map; + this.of = of; + this.ap = ap; +} + +var Monad = /*#__PURE__*/I.inherit(function Monad(map, of, ap, chain) { + if (!this) return freezeInDev(new Monad(map, of, ap, chain)); + Applicative.call(this, map, of, ap); + this.chain = chain; +}, Applicative); + +// + +var ConstantWith = function ConstantWith(ap, empty) { + return Applicative(I.sndU, I.always(empty), ap); }; -var ConcatOf = function ConcatOf(ap, empty) { - return { map: I.sndU, ap: ap, of: I.always(empty) }; +var ConstantOf = function ConstantOf(_ref) { + var concat = _ref.concat, + empty = _ref.empty; + return ConstantWith(concat, empty()); }; -var Sum = /*#__PURE__*/ConcatOf(addU, 0); +var Sum = /*#__PURE__*/ConstantWith(addU, 0); var mumBy = function mumBy(ord) { return I.curry(function mumBy(xi2y, t, s) { @@ -421,12 +438,6 @@ var reqMaybeArray = function reqMaybeArray(msg) { // -var reqApplicative = function reqApplicative(name, arg) { - return function (C) { - if (!C.of) errorGiven('`' + name + (arg ? '(' + arg + ')' : '') + '` requires an applicative', C, 'Note that you cannot `get` a traversal. Perhaps you wanted to `collect` it?'); - }; -}; - var reqMonad = function reqMonad(name) { return function (C) { if (!C.chain) errorGiven('`' + name + '` requires a monad', C, 'Note that you can only `modify`, `remove`, `set`, and `traverse` a transform.'); @@ -485,17 +496,20 @@ function traversePartialIndex(A, xi2yA, xs, skip) { // -var ConstantLog = { - map: function map(f, _ref) { - var m = _ref.m, - p = _ref.p, - c = _ref.c; - return { m: '%O <= ' + m, p: [f(p[0]), p], c: c }; - } -}; -var getLogFn = function getLogFn(x) { - return { m: '%O', p: [x, consExcept], c: x }; -}; +var SelectLog = /*#__PURE__*/Applicative(function (f, _ref2) { + var p = _ref2.p, + x = _ref2.x, + c = _ref2.c; + + x = f(x); + if (!I.isFunction(x)) p = [x, p]; + return { p: p, x: x, c: c }; +}, function (x) { + return { p: [], x: x, c: undefined }; +}, function (l, r) { + var v = undefined !== l.c ? l : r; + return { p: v.p, x: l.x(r.x), c: v.c }; +}); // @@ -610,53 +624,30 @@ var modifyAsyncU = function modifyAsyncU(o, f, s) { return returnAsync(toFunction(o)(s, void 0, IdentityAsync, f)); }; -function makeIx(i) { - var ix = function ix(s, j) { - return ix.v = j, s; - }; - ix.v = i; - return ix; -} - -function getNestedU(l, s, j, ix) { - for (var n = l.length, o; j < n; ++j) { - switch (typeof (o = l[j])) { - case 'string': - s = getProp(ix.v = o, s); - break; - case 'number': - s = getIndex(ix.v = o, s); - break; - case 'object': - s = getNestedU(o, s, 0, ix); - break; - default: - s = o(s, ix.v, Constant, ix); - } - }return s; -} - -var getU = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(0, ef(reqOptic)))(function (l, s) { +var getAsU = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(1, ef(reqOptic)))(function getAs(xi2y, l, s) { switch (typeof l) { case 'string': - return getProp(l, s); + return xi2y(getProp(l, s), l); case 'number': - return getIndex(l, s); + return xi2y(getIndex(l, s), l); case 'object': - for (var i = 0, n = l.length, o; i < n; ++i) { - switch (typeof (o = l[i])) { - case 'string': - s = getProp(o, s); - break; - case 'number': - s = getIndex(o, s); - break; - default: - return getNestedU(l, s, i, makeIx(l[i - 1])); - } - }return s; + { + var n = l.length; + for (var i = 0, o; i < n; ++i) { + switch (typeof (o = l[i])) { + case 'string': + s = getProp(o, s); + break; + case 'number': + s = getIndex(o, s); + break; + default: + return composed(i, l)(s, l[i - 1], Select, xi2y); + } + }return xi2y(s, l[n - 1]); + } default: - return l(s, void 0, Constant, id); + return xi2y !== id && l.length !== 4 ? xi2y(l(s, void 0), void 0) : l(s, void 0, Select, xi2y); } }); @@ -714,7 +705,7 @@ var getPick = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : res(I.f var r = void 0; for (var k in template) { var t = template[k]; - var v = I.isObject(t) ? getPick(t, x) : getU(t, x); + var v = I.isObject(t) ? getPick(t, x) : getAsU(id, t, x); if (void 0 !== v) { if (!r) r = {}; r[k] = v; @@ -1050,10 +1041,9 @@ var orElseU = function orElse(back, prim) { }; }; -function zeroOp(y, i, C, xi2yC, x) { - var of = C.of; - return of ? of(y) : C.map(I.always(y), xi2yC(x, i)); -} +var zero = function zero(x, _i, C, _xi2yC) { + return C.of(x); +}; // @@ -1079,13 +1069,6 @@ var pickInAux = function pickInAux(t, k) { // -var condOfDefault = /*#__PURE__*/I.always(zeroOp); -var condOfCase = function condOfCase(p, o, r) { - return function (y, j) { - return p(y, j) ? o : r(y, j); - }; -}; - // Auxiliary var seemsArrayLike = function seemsArrayLike(x) { @@ -1094,28 +1077,18 @@ var seemsArrayLike = function seemsArrayLike(x) { // Internals -var Identity = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : I.freeze)({ - map: I.applyU, - of: id, - ap: I.applyU, - chain: I.applyU -}); +var Identity = /*#__PURE__*/Monad(I.applyU, id, I.applyU, I.applyU); -var IdentityAsync = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : I.freeze)({ - map: chainAsync, - ap: function ap(xyP, xP) { - return chainAsync(function (xP) { - return chainAsync(function (xyP) { - return xyP(xP); - }, xyP); - }, xP); - }, - of: id, - chain: chainAsync -}); +var IdentityAsync = /*#__PURE__*/Monad(chainAsync, id, function (xyP, xP) { + return chainAsync(function (xP) { + return chainAsync(function (xyP) { + return xyP(xP); + }, xyP); + }, xP); +}, chainAsync); -var Constant = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : I.freeze)({ - map: I.sndU +var Select = /*#__PURE__*/ConstantWith(function (l, r) { + return void 0 !== l ? l : r; }); var toFunction = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(0, ef(reqOptic)))(function toFunction(o) { @@ -1234,14 +1207,38 @@ var condOf = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : function }; })(function condOf(of) { of = toFunction(of); - var op = condOfDefault; - var n = arguments.length; - while (--n) { - var c = arguments[n]; - op = c.length === 1 ? I.always(toFunction(c[0])) : condOfCase(c[0], toFunction(c[1]), op); + + var n = arguments.length - 1; + if (!n) return zero; + + var def = arguments[n]; + if (def.length === 1) { + --n; + def = toFunction(def[0]); + } else { + def = zero; + } + + var ps = Array(n); + var os = Array(n + 1); + for (var i = 0; i < n; ++i) { + var c = arguments[i + 1]; + ps[i] = c[0]; + os[i] = toFunction(c[1]); } - return function condOf(x, i, C, xi2yC) { - return of(x, i, Constant, op)(x, i, C, xi2yC); + os[n] = def; + + return function condOf(x, i, F, xi2yF) { + var min = n; + of(x, i, Select, function (y, j) { + for (var _i3 = 0; _i3 < min; ++_i3) { + if (ps[_i3](y, j)) { + min = _i3; + if (_i3 === 0) return 0;else break; + } + } + }); + return os[min](x, i, F, xi2yF); }; }); @@ -1249,19 +1246,6 @@ var ifElse = /*#__PURE__*/I.curry(function ifElse(c, t, e) { return eitherU(toFunction(t), toFunction(e))(c); }); -var iftes = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : function (fn$$1) { - return function iftes(_c, _t) { - warn(iftes, '`iftes` has been obsoleted. Use `ifElse` or `cond` instead. See CHANGELOG for details.'); - return fn$$1.apply(null, arguments); - }; -})(function iftes(_c, _t) { - var n = arguments.length; - var r = n & 1 ? toFunction(arguments[--n]) : zero; - while (0 <= (n -= 2)) { - r = eitherU(toFunction(arguments[n + 1]), r)(arguments[n]); - }return r; -}); - var orElse = /*#__PURE__*/I.curry(orElseU); // Querying @@ -1280,16 +1264,12 @@ var choice = function choice() { return os.reduceRight(orElseU, zero); }; -var unless = /*#__PURE__*/eitherU(zeroOp, identity); +var unless = /*#__PURE__*/eitherU(zero, identity); -var when = /*#__PURE__*/eitherU(identity, zeroOp); +var when = /*#__PURE__*/eitherU(identity, zero); var optional = /*#__PURE__*/when(I.isDefined); -var zero = function zero(x, i, C, xi2yC) { - return zeroOp(x, i, C, xi2yC); -}; - // Indices var mapIx = function mapIx(ix2j) { @@ -1321,6 +1301,20 @@ var skipIx = /*#__PURE__*/setName( /*#__PURE__*/tieIx(I.sndU), 'skipIx'); // Debugging +function getLog(l, s) { + var _traverseU = traverseU(SelectLog, function (x) { + return { p: [x, consExcept], x: x, c: x }; + }, l, s), + p = _traverseU.p, + c = _traverseU.c; + + p = pushTo(p, ['%O']); + for (var i = 2; i < p.length; ++i) { + p[0] += ' <= %O'; + }console.log.apply(console, p); + return c; +} + function log() { var show = I.curry(function log(dir, x) { console.log.apply(console, copyToFrom([], 0, arguments, 0, arguments.length).concat([dir, x])); @@ -1329,16 +1323,6 @@ function log() { return isoU(show('get'), show('set')); } -var getLog = /*#__PURE__*/I.curry(function getLog(l, s) { - var _traverseU = traverseU(ConstantLog, getLogFn, l, s), - m = _traverseU.m, - p = _traverseU.p, - c = _traverseU.c; - - console.log.apply(console, pushTo(p, [m])); - return c; -}); - // Operations on transforms var transform = /*#__PURE__*/I.curry(function transform(o, s) { @@ -1374,14 +1358,14 @@ var assignOp = function assignOp(x) { }; var modifyOp = function modifyOp(xi2y) { - return function modifyOp(x, i, C, xi2yC) { - return zeroOp(x = xi2y(x, i), i, C, xi2yC, x); + return function modifyOp(x, i, C, _xi2yC) { + return C.of(xi2y(x, i)); }; }; var setOp = function setOp(y) { - return function setOp(_x, i, C, xi2yC) { - return zeroOp(y, i, C, xi2yC, y); + return function setOp(_x, _i, C, _xi2yC) { + return C.of(y); }; }; @@ -1408,9 +1392,9 @@ function branches() { // Traversals and combinators -var elems = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(2, ef(reqApplicative('elems'))))(function elems(xs, i, A, xi2yA) { +function elems(xs, i, A, xi2yA) { return seemsArrayLike(xs) ? elemsI(xs, i, A, xi2yA) : A.of(xs); -}); +} var elemsTotal = function elemsTotal(xs, i, A, xi2yA) { return seemsArrayLike(xs) ? A === Identity ? mapPartialIndexU(xi2yA, xs, mapPartialIndexU) : A === Select ? selectInArrayLike(xi2yA, xs) : traversePartialIndex(A, xi2yA, xs, traversePartialIndex) : A.of(xs); @@ -1420,9 +1404,7 @@ var entries = /*#__PURE__*/setName( /*#__PURE__*/toFunction([keyed, elems]), 'en var keys = /*#__PURE__*/setName( /*#__PURE__*/toFunction([keyed, elems, 0]), 'keys'); -var matches = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : dep(function (re) { - return re.global ? res(par(2, ef(reqApplicative('matches', re)))) : id; -}))(function matches(re) { +function matches(re) { return function matches(x, _i, C, xi2yC) { if (I.isString(x)) { var map = C.map; @@ -1446,22 +1428,22 @@ var matches = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : dep(fun }, xi2yC(m[0], reIndex(m))); } } - return zeroOp(x, void 0, C, xi2yC); + return C.of(x); }; -}); +} -var values = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(2, ef(reqApplicative('values'))))( /*#__PURE__*/setName( /*#__PURE__*/branchOr1Level(identity, protoless0), 'values')); +var values = /*#__PURE__*/setName( /*#__PURE__*/branchOr1Level(identity, protoless0), 'values'); -var children = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(2, ef(reqApplicative('children'))))(function children(x, i, C, xi2yC) { +function children(x, i, C, xi2yC) { return I.isArray(x) ? elemsI(x, i, C, xi2yC) : I.isObject(x) ? values(x, i, C, xi2yC) : C.of(x); -}); +} -var flatten = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(2, ef(reqApplicative('flatten'))))(function flatten(x, i, C, xi2yC) { +function flatten(x, i, C, xi2yC) { var rec = function rec(x, i) { return I.isArray(x) ? elemsI(x, i, C, rec) : void 0 !== x ? xi2yC(x, i) : C.of(x); }; return rec(x, i); -}); +} function query() { var r = []; @@ -1488,7 +1470,7 @@ var leafs = /*#__PURE__*/satisfying(function (x) { // Folds over traversals var all = /*#__PURE__*/I.curry(function all(xi2b, t, s) { - return !traverseU(Select, function (x, i) { + return !getAsU(function (x, i) { if (!xi2b(x, i)) return true; }, t, s); }); @@ -1496,7 +1478,7 @@ var all = /*#__PURE__*/I.curry(function all(xi2b, t, s) { var and$1 = /*#__PURE__*/all(id); var any = /*#__PURE__*/I.curry(function any(xi2b, t, s) { - return !!traverseU(Select, function (x, i) { + return !!getAsU(function (x, i) { if (xi2b(x, i)) return true; }, t, s); }); @@ -1512,9 +1494,7 @@ var collectAs = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? I.curry : var collect = /*#__PURE__*/collectAs(id); -var concatAs = /*#__PURE__*/mkTraverse(id, function concatAs(m) { - return ConcatOf(m.concat, m.empty()); -}); +var concatAs = /*#__PURE__*/mkTraverse(id, ConstantOf); var concat = /*#__PURE__*/concatAs(id); @@ -1571,16 +1551,24 @@ var forEachWith = /*#__PURE__*/I.curry(function forEachWith(newC, ef$$1, t, s) { return c; }); +function get(l, s) { + return 1 < arguments.length ? getAsU(id, l, s) : function (s) { + return getAsU(id, l, s); + }; +} + +var getAs = /*#__PURE__*/I.curry(getAsU); + var isDefined = /*#__PURE__*/I.curry(function isDefined(t, s) { - return void 0 !== traverseU(Select, id, t, s); + return void 0 !== getAsU(id, t, s); }); var isEmpty = /*#__PURE__*/I.curry(function isEmpty(t, s) { - return !traverseU(Select, I.always(true), t, s); + return !getAsU(toTrue, t, s); }); var joinAs = /*#__PURE__*/mkTraverse(toStringPartial, /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : par(0, ef(reqString('`join` and `joinAs` expect a string delimiter'))))(function joinAs(d) { - return ConcatOf(function (x, y) { + return ConstantWith(function (x, y) { return void 0 !== x ? void 0 !== y ? x + d + y : x : y; }); })); @@ -1611,33 +1599,31 @@ var minimumBy = /*#__PURE__*/mumBy(ltU); var minimum = /*#__PURE__*/minimumBy(id); var none = /*#__PURE__*/I.curry(function none(xi2b, t, s) { - return !traverseU(Select, function (x, i) { + return !getAsU(function (x, i) { if (xi2b(x, i)) return true; }, t, s); }); var or$1 = /*#__PURE__*/any(id); -var productAs = /*#__PURE__*/traverse( /*#__PURE__*/ConcatOf(multiplyU, 1)); +var productAs = /*#__PURE__*/traverse( /*#__PURE__*/ConstantWith(multiplyU, 1)); var product = /*#__PURE__*/productAs( /*#__PURE__*/unto(1)); -var selectAs = /*#__PURE__*/traverse(Select); +var select = process.env.NODE_ENV === 'production' ? get : /*#__PURE__*/I.curry(function select(l, s) { + warn(select, '`select` has been obsoleted. Just use `get`. See CHANGELOG for details.'); + return get(l, s); +}); -var select = /*#__PURE__*/selectAs(id); +var selectAs = process.env.NODE_ENV === 'production' ? getAs : /*#__PURE__*/I.curry(function selectAs(f, l, s) { + warn(selectAs, '`selectAs` has been obsoleted. Just use `getAs`. See CHANGELOG for details.'); + return getAs(f, l, s); +}); var sumAs = /*#__PURE__*/traverse(Sum); var sum = /*#__PURE__*/sumAs(unto0); -// Operations on lenses - -function get(l, s) { - return 1 < arguments.length ? getU(l, s) : function (s) { - return getU(l, s); - }; -} - // Creating new lenses var lens = /*#__PURE__*/I.curry(lensU); @@ -1873,7 +1859,7 @@ var array = function array(elem) { var inverse = function inverse(iso) { return function (x, i, F, xi2yF) { return F.map(function (x) { - return getU(iso, x); + return getAsU(id, iso, x); }, xi2yF(setU(iso, x, void 0), i)); }; }; @@ -1907,10 +1893,10 @@ var indexed = /*#__PURE__*/isoU( /*#__PURE__*/expect(seemsArrayLike, /*#__PURE__ } n = xs.length; var j = 0; - for (var _i3 = 0; _i3 < n; ++_i3) { - var x = xs[_i3]; + for (var _i4 = 0; _i4 < n; ++_i4) { + var x = xs[_i4]; if (void 0 !== x) { - if (_i3 !== j) xs[j] = x; + if (_i4 !== j) xs[j] = x; ++j; } } @@ -1944,10 +1930,10 @@ var uriComponent = /*#__PURE__*/stringIsoU(decodeURIComponent, encodeURIComponen var json = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id : res(function (iso) { return toFunction([iso, isoU(deepFreeze, id)]); }))(function json(options) { - var _ref2 = options || I.object0, - reviver = _ref2.reviver, - replacer = _ref2.replacer, - space = _ref2.space; + var _ref3 = options || I.object0, + reviver = _ref3.reviver, + replacer = _ref3.replacer, + space = _ref3.space; return isoU(expect(I.isString, function (text) { return JSON.parse(text, reviver); @@ -2028,7 +2014,7 @@ var subtract = function subtract(c) { // Interop var pointer = function pointer(s) { - if (s[0] === '#') s = getU(uriComponent, s); + if (s[0] === '#') s = getAsU(id, uriComponent, s); var ts = s.split('/'); var n = ts.length; for (var i = 1; i < n; ++i) { @@ -2042,7 +2028,7 @@ var pointer = function pointer(s) { exports.seemsArrayLike = seemsArrayLike; exports.Identity = Identity; exports.IdentityAsync = IdentityAsync; -exports.Constant = Constant; +exports.Select = Select; exports.toFunction = toFunction; exports.assign = assign; exports.modify = modify; @@ -2058,7 +2044,6 @@ exports.choose = choose; exports.cond = cond; exports.condOf = condOf; exports.ifElse = ifElse; -exports.iftes = iftes; exports.orElse = orElse; exports.chain = chain; exports.choice = choice; @@ -2071,8 +2056,8 @@ exports.setIx = setIx; exports.tieIx = tieIx; exports.joinIx = joinIx; exports.skipIx = skipIx; -exports.log = log; exports.getLog = getLog; +exports.log = log; exports.transform = transform; exports.transformAsync = transformAsync; exports.seq = seq; @@ -2109,6 +2094,8 @@ exports.foldl = foldl; exports.foldr = foldr; exports.forEach = forEach; exports.forEachWith = forEachWith; +exports.get = get; +exports.getAs = getAs; exports.isDefined = isDefined; exports.isEmpty = isEmpty; exports.joinAs = joinAs; @@ -2123,11 +2110,10 @@ exports.none = none; exports.or = or$1; exports.productAs = productAs; exports.product = product; -exports.selectAs = selectAs; exports.select = select; +exports.selectAs = selectAs; exports.sumAs = sumAs; exports.sum = sum; -exports.get = get; exports.lens = lens; exports.getter = getter; exports.setter = setter; diff --git a/dist/partial.lenses.es.js b/dist/partial.lenses.es.js index c20e3262..cf02fa74 100644 --- a/dist/partial.lenses.es.js +++ b/dist/partial.lenses.es.js @@ -1,4 +1,4 @@ -import { defineNameU, isString, isFunction, isArray, freeze, isObject, acyclicEqualsU, array0, object0, sndU, always, curry, curryN, assocPartialU, dissocPartialU, isNumber, constructorOf, toObject, applyU, isDefined, keys, hasU, arityN, id, assign } from 'infestines'; +import { defineNameU, isString, isFunction, always, freeze, isArray, isObject, acyclicEqualsU, array0, object0, inherit, sndU, curry, curryN, assocPartialU, dissocPartialU, isNumber, constructorOf, toObject, applyU, isDefined, keys, hasU, arityN, id, assign } from 'infestines'; var addU = function addU(x, y) { return x + y; @@ -190,6 +190,8 @@ var unto = function unto(c) { }; var unto0 = /*#__PURE__*/unto(0); +var toTrue = /*#__PURE__*/always(true); + var notPartial = function complement(x) { return void 0 !== x ? !x : x; }; @@ -204,6 +206,8 @@ var expect = function expect(p, f) { }, f); }; +var freezeInDev = process.env.NODE_ENV === 'production' ? id$1 : freeze; + function deepFreeze(x) { if (isArray(x)) { x.forEach(deepFreeze); @@ -312,19 +316,32 @@ function selectInArrayLike(xi2v, xs) { // -var Select = { - map: sndU, - of: function of() {}, - ap: function ap(l, r) { - return void 0 !== l ? l : r; - } +function Applicative(map, of, ap) { + if (!this) return freezeInDev(new Applicative(map, of, ap)); + this.map = map; + this.of = of; + this.ap = ap; +} + +var Monad = /*#__PURE__*/inherit(function Monad(map, of, ap, chain) { + if (!this) return freezeInDev(new Monad(map, of, ap, chain)); + Applicative.call(this, map, of, ap); + this.chain = chain; +}, Applicative); + +// + +var ConstantWith = function ConstantWith(ap, empty) { + return Applicative(sndU, always(empty), ap); }; -var ConcatOf = function ConcatOf(ap, empty) { - return { map: sndU, ap: ap, of: always(empty) }; +var ConstantOf = function ConstantOf(_ref) { + var concat = _ref.concat, + empty = _ref.empty; + return ConstantWith(concat, empty()); }; -var Sum = /*#__PURE__*/ConcatOf(addU, 0); +var Sum = /*#__PURE__*/ConstantWith(addU, 0); var mumBy = function mumBy(ord) { return curry(function mumBy(xi2y, t, s) { @@ -417,12 +434,6 @@ var reqMaybeArray = function reqMaybeArray(msg) { // -var reqApplicative = function reqApplicative(name, arg) { - return function (C) { - if (!C.of) errorGiven('`' + name + (arg ? '(' + arg + ')' : '') + '` requires an applicative', C, 'Note that you cannot `get` a traversal. Perhaps you wanted to `collect` it?'); - }; -}; - var reqMonad = function reqMonad(name) { return function (C) { if (!C.chain) errorGiven('`' + name + '` requires a monad', C, 'Note that you can only `modify`, `remove`, `set`, and `traverse` a transform.'); @@ -481,17 +492,20 @@ function traversePartialIndex(A, xi2yA, xs, skip) { // -var ConstantLog = { - map: function map(f, _ref) { - var m = _ref.m, - p = _ref.p, - c = _ref.c; - return { m: '%O <= ' + m, p: [f(p[0]), p], c: c }; - } -}; -var getLogFn = function getLogFn(x) { - return { m: '%O', p: [x, consExcept], c: x }; -}; +var SelectLog = /*#__PURE__*/Applicative(function (f, _ref2) { + var p = _ref2.p, + x = _ref2.x, + c = _ref2.c; + + x = f(x); + if (!isFunction(x)) p = [x, p]; + return { p: p, x: x, c: c }; +}, function (x) { + return { p: [], x: x, c: undefined }; +}, function (l, r) { + var v = undefined !== l.c ? l : r; + return { p: v.p, x: l.x(r.x), c: v.c }; +}); // @@ -606,53 +620,30 @@ var modifyAsyncU = function modifyAsyncU(o, f, s) { return returnAsync(toFunction(o)(s, void 0, IdentityAsync, f)); }; -function makeIx(i) { - var ix = function ix(s, j) { - return ix.v = j, s; - }; - ix.v = i; - return ix; -} - -function getNestedU(l, s, j, ix) { - for (var n = l.length, o; j < n; ++j) { - switch (typeof (o = l[j])) { - case 'string': - s = getProp(ix.v = o, s); - break; - case 'number': - s = getIndex(ix.v = o, s); - break; - case 'object': - s = getNestedU(o, s, 0, ix); - break; - default: - s = o(s, ix.v, Constant, ix); - } - }return s; -} - -var getU = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(0, ef(reqOptic)))(function (l, s) { +var getAsU = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(1, ef(reqOptic)))(function getAs(xi2y, l, s) { switch (typeof l) { case 'string': - return getProp(l, s); + return xi2y(getProp(l, s), l); case 'number': - return getIndex(l, s); + return xi2y(getIndex(l, s), l); case 'object': - for (var i = 0, n = l.length, o; i < n; ++i) { - switch (typeof (o = l[i])) { - case 'string': - s = getProp(o, s); - break; - case 'number': - s = getIndex(o, s); - break; - default: - return getNestedU(l, s, i, makeIx(l[i - 1])); - } - }return s; + { + var n = l.length; + for (var i = 0, o; i < n; ++i) { + switch (typeof (o = l[i])) { + case 'string': + s = getProp(o, s); + break; + case 'number': + s = getIndex(o, s); + break; + default: + return composed(i, l)(s, l[i - 1], Select, xi2y); + } + }return xi2y(s, l[n - 1]); + } default: - return l(s, void 0, Constant, id$1); + return xi2y !== id$1 && l.length !== 4 ? xi2y(l(s, void 0), void 0) : l(s, void 0, Select, xi2y); } }); @@ -710,7 +701,7 @@ var getPick = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : res(f var r = void 0; for (var k in template) { var t = template[k]; - var v = isObject(t) ? getPick(t, x) : getU(t, x); + var v = isObject(t) ? getPick(t, x) : getAsU(id$1, t, x); if (void 0 !== v) { if (!r) r = {}; r[k] = v; @@ -1046,10 +1037,9 @@ var orElseU = function orElse(back, prim) { }; }; -function zeroOp(y, i, C, xi2yC, x) { - var of = C.of; - return of ? of(y) : C.map(always(y), xi2yC(x, i)); -} +var zero = function zero(x, _i, C, _xi2yC) { + return C.of(x); +}; // @@ -1075,13 +1065,6 @@ var pickInAux = function pickInAux(t, k) { // -var condOfDefault = /*#__PURE__*/always(zeroOp); -var condOfCase = function condOfCase(p, o, r) { - return function (y, j) { - return p(y, j) ? o : r(y, j); - }; -}; - // Auxiliary var seemsArrayLike = function seemsArrayLike(x) { @@ -1090,28 +1073,18 @@ var seemsArrayLike = function seemsArrayLike(x) { // Internals -var Identity = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : freeze)({ - map: applyU, - of: id$1, - ap: applyU, - chain: applyU -}); +var Identity = /*#__PURE__*/Monad(applyU, id$1, applyU, applyU); -var IdentityAsync = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : freeze)({ - map: chainAsync, - ap: function ap(xyP, xP) { - return chainAsync(function (xP) { - return chainAsync(function (xyP) { - return xyP(xP); - }, xyP); - }, xP); - }, - of: id$1, - chain: chainAsync -}); +var IdentityAsync = /*#__PURE__*/Monad(chainAsync, id$1, function (xyP, xP) { + return chainAsync(function (xP) { + return chainAsync(function (xyP) { + return xyP(xP); + }, xyP); + }, xP); +}, chainAsync); -var Constant = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : freeze)({ - map: sndU +var Select = /*#__PURE__*/ConstantWith(function (l, r) { + return void 0 !== l ? l : r; }); var toFunction = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(0, ef(reqOptic)))(function toFunction(o) { @@ -1230,14 +1203,38 @@ var condOf = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : functi }; })(function condOf(of) { of = toFunction(of); - var op = condOfDefault; - var n = arguments.length; - while (--n) { - var c = arguments[n]; - op = c.length === 1 ? always(toFunction(c[0])) : condOfCase(c[0], toFunction(c[1]), op); + + var n = arguments.length - 1; + if (!n) return zero; + + var def = arguments[n]; + if (def.length === 1) { + --n; + def = toFunction(def[0]); + } else { + def = zero; + } + + var ps = Array(n); + var os = Array(n + 1); + for (var i = 0; i < n; ++i) { + var c = arguments[i + 1]; + ps[i] = c[0]; + os[i] = toFunction(c[1]); } - return function condOf(x, i, C, xi2yC) { - return of(x, i, Constant, op)(x, i, C, xi2yC); + os[n] = def; + + return function condOf(x, i, F, xi2yF) { + var min = n; + of(x, i, Select, function (y, j) { + for (var _i3 = 0; _i3 < min; ++_i3) { + if (ps[_i3](y, j)) { + min = _i3; + if (_i3 === 0) return 0;else break; + } + } + }); + return os[min](x, i, F, xi2yF); }; }); @@ -1245,19 +1242,6 @@ var ifElse = /*#__PURE__*/curry(function ifElse(c, t, e) { return eitherU(toFunction(t), toFunction(e))(c); }); -var iftes = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : function (fn$$1) { - return function iftes(_c, _t) { - warn(iftes, '`iftes` has been obsoleted. Use `ifElse` or `cond` instead. See CHANGELOG for details.'); - return fn$$1.apply(null, arguments); - }; -})(function iftes(_c, _t) { - var n = arguments.length; - var r = n & 1 ? toFunction(arguments[--n]) : zero; - while (0 <= (n -= 2)) { - r = eitherU(toFunction(arguments[n + 1]), r)(arguments[n]); - }return r; -}); - var orElse = /*#__PURE__*/curry(orElseU); // Querying @@ -1276,16 +1260,12 @@ var choice = function choice() { return os.reduceRight(orElseU, zero); }; -var unless = /*#__PURE__*/eitherU(zeroOp, identity); +var unless = /*#__PURE__*/eitherU(zero, identity); -var when = /*#__PURE__*/eitherU(identity, zeroOp); +var when = /*#__PURE__*/eitherU(identity, zero); var optional = /*#__PURE__*/when(isDefined); -var zero = function zero(x, i, C, xi2yC) { - return zeroOp(x, i, C, xi2yC); -}; - // Indices var mapIx = function mapIx(ix2j) { @@ -1317,6 +1297,20 @@ var skipIx = /*#__PURE__*/setName( /*#__PURE__*/tieIx(sndU), 'skipIx'); // Debugging +function getLog(l, s) { + var _traverseU = traverseU(SelectLog, function (x) { + return { p: [x, consExcept], x: x, c: x }; + }, l, s), + p = _traverseU.p, + c = _traverseU.c; + + p = pushTo(p, ['%O']); + for (var i = 2; i < p.length; ++i) { + p[0] += ' <= %O'; + }console.log.apply(console, p); + return c; +} + function log() { var show = curry(function log(dir, x) { console.log.apply(console, copyToFrom([], 0, arguments, 0, arguments.length).concat([dir, x])); @@ -1325,16 +1319,6 @@ function log() { return isoU(show('get'), show('set')); } -var getLog = /*#__PURE__*/curry(function getLog(l, s) { - var _traverseU = traverseU(ConstantLog, getLogFn, l, s), - m = _traverseU.m, - p = _traverseU.p, - c = _traverseU.c; - - console.log.apply(console, pushTo(p, [m])); - return c; -}); - // Operations on transforms var transform = /*#__PURE__*/curry(function transform(o, s) { @@ -1370,14 +1354,14 @@ var assignOp = function assignOp(x) { }; var modifyOp = function modifyOp(xi2y) { - return function modifyOp(x, i, C, xi2yC) { - return zeroOp(x = xi2y(x, i), i, C, xi2yC, x); + return function modifyOp(x, i, C, _xi2yC) { + return C.of(xi2y(x, i)); }; }; var setOp = function setOp(y) { - return function setOp(_x, i, C, xi2yC) { - return zeroOp(y, i, C, xi2yC, y); + return function setOp(_x, _i, C, _xi2yC) { + return C.of(y); }; }; @@ -1404,9 +1388,9 @@ function branches() { // Traversals and combinators -var elems = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(2, ef(reqApplicative('elems'))))(function elems(xs, i, A, xi2yA) { +function elems(xs, i, A, xi2yA) { return seemsArrayLike(xs) ? elemsI(xs, i, A, xi2yA) : A.of(xs); -}); +} var elemsTotal = function elemsTotal(xs, i, A, xi2yA) { return seemsArrayLike(xs) ? A === Identity ? mapPartialIndexU(xi2yA, xs, mapPartialIndexU) : A === Select ? selectInArrayLike(xi2yA, xs) : traversePartialIndex(A, xi2yA, xs, traversePartialIndex) : A.of(xs); @@ -1416,9 +1400,7 @@ var entries = /*#__PURE__*/setName( /*#__PURE__*/toFunction([keyed, elems]), 'en var keys$1 = /*#__PURE__*/setName( /*#__PURE__*/toFunction([keyed, elems, 0]), 'keys'); -var matches = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : dep(function (re) { - return re.global ? res(par(2, ef(reqApplicative('matches', re)))) : id$1; -}))(function matches(re) { +function matches(re) { return function matches(x, _i, C, xi2yC) { if (isString(x)) { var map = C.map; @@ -1442,22 +1424,22 @@ var matches = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : dep(f }, xi2yC(m[0], reIndex(m))); } } - return zeroOp(x, void 0, C, xi2yC); + return C.of(x); }; -}); +} -var values = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(2, ef(reqApplicative('values'))))( /*#__PURE__*/setName( /*#__PURE__*/branchOr1Level(identity, protoless0), 'values')); +var values = /*#__PURE__*/setName( /*#__PURE__*/branchOr1Level(identity, protoless0), 'values'); -var children = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(2, ef(reqApplicative('children'))))(function children(x, i, C, xi2yC) { +function children(x, i, C, xi2yC) { return isArray(x) ? elemsI(x, i, C, xi2yC) : isObject(x) ? values(x, i, C, xi2yC) : C.of(x); -}); +} -var flatten = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(2, ef(reqApplicative('flatten'))))(function flatten(x, i, C, xi2yC) { +function flatten(x, i, C, xi2yC) { var rec = function rec(x, i) { return isArray(x) ? elemsI(x, i, C, rec) : void 0 !== x ? xi2yC(x, i) : C.of(x); }; return rec(x, i); -}); +} function query() { var r = []; @@ -1484,7 +1466,7 @@ var leafs = /*#__PURE__*/satisfying(function (x) { // Folds over traversals var all = /*#__PURE__*/curry(function all(xi2b, t, s) { - return !traverseU(Select, function (x, i) { + return !getAsU(function (x, i) { if (!xi2b(x, i)) return true; }, t, s); }); @@ -1492,7 +1474,7 @@ var all = /*#__PURE__*/curry(function all(xi2b, t, s) { var and$1 = /*#__PURE__*/all(id$1); var any = /*#__PURE__*/curry(function any(xi2b, t, s) { - return !!traverseU(Select, function (x, i) { + return !!getAsU(function (x, i) { if (xi2b(x, i)) return true; }, t, s); }); @@ -1508,9 +1490,7 @@ var collectAs = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? curry : re var collect = /*#__PURE__*/collectAs(id$1); -var concatAs = /*#__PURE__*/mkTraverse(id$1, function concatAs(m) { - return ConcatOf(m.concat, m.empty()); -}); +var concatAs = /*#__PURE__*/mkTraverse(id$1, ConstantOf); var concat = /*#__PURE__*/concatAs(id$1); @@ -1567,16 +1547,24 @@ var forEachWith = /*#__PURE__*/curry(function forEachWith(newC, ef$$1, t, s) { return c; }); +function get(l, s) { + return 1 < arguments.length ? getAsU(id$1, l, s) : function (s) { + return getAsU(id$1, l, s); + }; +} + +var getAs = /*#__PURE__*/curry(getAsU); + var isDefined$1 = /*#__PURE__*/curry(function isDefined$$1(t, s) { - return void 0 !== traverseU(Select, id$1, t, s); + return void 0 !== getAsU(id$1, t, s); }); var isEmpty = /*#__PURE__*/curry(function isEmpty(t, s) { - return !traverseU(Select, always(true), t, s); + return !getAsU(toTrue, t, s); }); var joinAs = /*#__PURE__*/mkTraverse(toStringPartial, /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : par(0, ef(reqString('`join` and `joinAs` expect a string delimiter'))))(function joinAs(d) { - return ConcatOf(function (x, y) { + return ConstantWith(function (x, y) { return void 0 !== x ? void 0 !== y ? x + d + y : x : y; }); })); @@ -1607,33 +1595,31 @@ var minimumBy = /*#__PURE__*/mumBy(ltU); var minimum = /*#__PURE__*/minimumBy(id$1); var none = /*#__PURE__*/curry(function none(xi2b, t, s) { - return !traverseU(Select, function (x, i) { + return !getAsU(function (x, i) { if (xi2b(x, i)) return true; }, t, s); }); var or$1 = /*#__PURE__*/any(id$1); -var productAs = /*#__PURE__*/traverse( /*#__PURE__*/ConcatOf(multiplyU, 1)); +var productAs = /*#__PURE__*/traverse( /*#__PURE__*/ConstantWith(multiplyU, 1)); var product = /*#__PURE__*/productAs( /*#__PURE__*/unto(1)); -var selectAs = /*#__PURE__*/traverse(Select); +var select = process.env.NODE_ENV === 'production' ? get : /*#__PURE__*/curry(function select(l, s) { + warn(select, '`select` has been obsoleted. Just use `get`. See CHANGELOG for details.'); + return get(l, s); +}); -var select = /*#__PURE__*/selectAs(id$1); +var selectAs = process.env.NODE_ENV === 'production' ? getAs : /*#__PURE__*/curry(function selectAs(f, l, s) { + warn(selectAs, '`selectAs` has been obsoleted. Just use `getAs`. See CHANGELOG for details.'); + return getAs(f, l, s); +}); var sumAs = /*#__PURE__*/traverse(Sum); var sum = /*#__PURE__*/sumAs(unto0); -// Operations on lenses - -function get(l, s) { - return 1 < arguments.length ? getU(l, s) : function (s) { - return getU(l, s); - }; -} - // Creating new lenses var lens = /*#__PURE__*/curry(lensU); @@ -1869,7 +1855,7 @@ var array = function array(elem) { var inverse = function inverse(iso) { return function (x, i, F, xi2yF) { return F.map(function (x) { - return getU(iso, x); + return getAsU(id$1, iso, x); }, xi2yF(setU(iso, x, void 0), i)); }; }; @@ -1903,10 +1889,10 @@ var indexed = /*#__PURE__*/isoU( /*#__PURE__*/expect(seemsArrayLike, /*#__PURE__ } n = xs.length; var j = 0; - for (var _i3 = 0; _i3 < n; ++_i3) { - var x = xs[_i3]; + for (var _i4 = 0; _i4 < n; ++_i4) { + var x = xs[_i4]; if (void 0 !== x) { - if (_i3 !== j) xs[j] = x; + if (_i4 !== j) xs[j] = x; ++j; } } @@ -1940,10 +1926,10 @@ var uriComponent = /*#__PURE__*/stringIsoU(decodeURIComponent, encodeURIComponen var json = /*#__PURE__*/(process.env.NODE_ENV === 'production' ? id$1 : res(function (iso) { return toFunction([iso, isoU(deepFreeze, id$1)]); }))(function json(options) { - var _ref2 = options || object0, - reviver = _ref2.reviver, - replacer = _ref2.replacer, - space = _ref2.space; + var _ref3 = options || object0, + reviver = _ref3.reviver, + replacer = _ref3.replacer, + space = _ref3.space; return isoU(expect(isString, function (text) { return JSON.parse(text, reviver); @@ -2024,7 +2010,7 @@ var subtract = function subtract(c) { // Interop var pointer = function pointer(s) { - if (s[0] === '#') s = getU(uriComponent, s); + if (s[0] === '#') s = getAsU(id$1, uriComponent, s); var ts = s.split('/'); var n = ts.length; for (var i = 1; i < n; ++i) { @@ -2035,4 +2021,4 @@ var pointer = function pointer(s) { return ts; }; -export { seemsArrayLike, Identity, IdentityAsync, Constant, toFunction, assign$1 as assign, modify, modifyAsync, remove, set, traverse, compose, flat, lazy, choices, choose, cond, condOf, ifElse, iftes, orElse, chain, choice, unless, when, optional, zero, mapIx, setIx, tieIx, joinIx, skipIx, log, getLog, transform, transformAsync, seq, assignOp, modifyOp, setOp, removeOp, branchOr, branch, branches, elems, elemsTotal, entries, keys$1 as keys, matches, values, children, flatten, query, satisfying, leafs, all, and$1 as and, any, collectAs, collect, concatAs, concat, countIf, count, countsAs, counts, foldl, foldr, forEach, forEachWith, isDefined$1 as isDefined, isEmpty, joinAs, join, maximumBy, maximum, meanAs, mean, minimumBy, minimum, none, or$1 as or, productAs, product, selectAs, select, sumAs, sum, get, lens, getter, setter, foldTraversalLens, defaults, define, normalize, required, reread, rewrite, append, filter, find, findWith, first, index, last, prefix, slice, suffix, pickIn, prop, props, propsOf, removable, valueOr, pick, replace$1 as replace, getInverse, iso, array, inverse, complement, identity, is, indexed, reverse, singleton, disjoint, keyed, uri, uriComponent, json, dropPrefix, dropSuffix, replaces, split, uncouple, add$1 as add, divide, multiply$1 as multiply, negate$1 as negate, subtract, pointer }; +export { seemsArrayLike, Identity, IdentityAsync, Select, toFunction, assign$1 as assign, modify, modifyAsync, remove, set, traverse, compose, flat, lazy, choices, choose, cond, condOf, ifElse, orElse, chain, choice, unless, when, optional, zero, mapIx, setIx, tieIx, joinIx, skipIx, getLog, log, transform, transformAsync, seq, assignOp, modifyOp, setOp, removeOp, branchOr, branch, branches, elems, elemsTotal, entries, keys$1 as keys, matches, values, children, flatten, query, satisfying, leafs, all, and$1 as and, any, collectAs, collect, concatAs, concat, countIf, count, countsAs, counts, foldl, foldr, forEach, forEachWith, get, getAs, isDefined$1 as isDefined, isEmpty, joinAs, join, maximumBy, maximum, meanAs, mean, minimumBy, minimum, none, or$1 as or, productAs, product, select, selectAs, sumAs, sum, lens, getter, setter, foldTraversalLens, defaults, define, normalize, required, reread, rewrite, append, filter, find, findWith, first, index, last, prefix, slice, suffix, pickIn, prop, props, propsOf, removable, valueOr, pick, replace$1 as replace, getInverse, iso, array, inverse, complement, identity, is, indexed, reverse, singleton, disjoint, keyed, uri, uriComponent, json, dropPrefix, dropSuffix, replaces, split, uncouple, add$1 as add, divide, multiply$1 as multiply, negate$1 as negate, subtract, pointer }; diff --git a/dist/partial.lenses.js b/dist/partial.lenses.js index 7f556c64..07756843 100644 --- a/dist/partial.lenses.js +++ b/dist/partial.lenses.js @@ -190,6 +190,8 @@ }; var unto0 = /*#__PURE__*/unto(0); + var toTrue = /*#__PURE__*/I.always(true); + var notPartial = function complement(x) { return void 0 !== x ? !x : x; }; @@ -204,6 +206,8 @@ }, f); }; + var freezeInDev = I.freeze; + function deepFreeze(x) { if (I.isArray(x)) { x.forEach(deepFreeze); @@ -312,19 +316,32 @@ // - var Select = { - map: I.sndU, - of: function of() {}, - ap: function ap(l, r) { - return void 0 !== l ? l : r; - } + function Applicative(map, of, ap) { + if (!this) return freezeInDev(new Applicative(map, of, ap)); + this.map = map; + this.of = of; + this.ap = ap; + } + + var Monad = /*#__PURE__*/I.inherit(function Monad(map, of, ap, chain) { + if (!this) return freezeInDev(new Monad(map, of, ap, chain)); + Applicative.call(this, map, of, ap); + this.chain = chain; + }, Applicative); + + // + + var ConstantWith = function ConstantWith(ap, empty) { + return Applicative(I.sndU, I.always(empty), ap); }; - var ConcatOf = function ConcatOf(ap, empty) { - return { map: I.sndU, ap: ap, of: I.always(empty) }; + var ConstantOf = function ConstantOf(_ref) { + var concat = _ref.concat, + empty = _ref.empty; + return ConstantWith(concat, empty()); }; - var Sum = /*#__PURE__*/ConcatOf(addU, 0); + var Sum = /*#__PURE__*/ConstantWith(addU, 0); var mumBy = function mumBy(ord) { return I.curry(function mumBy(xi2y, t, s) { @@ -417,12 +434,6 @@ // - var reqApplicative = function reqApplicative(name, arg) { - return function (C) { - if (!C.of) errorGiven('`' + name + (arg ? '(' + arg + ')' : '') + '` requires an applicative', C, 'Note that you cannot `get` a traversal. Perhaps you wanted to `collect` it?'); - }; - }; - var reqMonad = function reqMonad(name) { return function (C) { if (!C.chain) errorGiven('`' + name + '` requires a monad', C, 'Note that you can only `modify`, `remove`, `set`, and `traverse` a transform.'); @@ -481,17 +492,20 @@ // - var ConstantLog = { - map: function map(f, _ref) { - var m = _ref.m, - p = _ref.p, - c = _ref.c; - return { m: '%O <= ' + m, p: [f(p[0]), p], c: c }; - } - }; - var getLogFn = function getLogFn(x) { - return { m: '%O', p: [x, consExcept], c: x }; - }; + var SelectLog = /*#__PURE__*/Applicative(function (f, _ref2) { + var p = _ref2.p, + x = _ref2.x, + c = _ref2.c; + + x = f(x); + if (!I.isFunction(x)) p = [x, p]; + return { p: p, x: x, c: c }; + }, function (x) { + return { p: [], x: x, c: undefined }; + }, function (l, r) { + var v = undefined !== l.c ? l : r; + return { p: v.p, x: l.x(r.x), c: v.c }; + }); // @@ -606,53 +620,30 @@ return returnAsync(toFunction(o)(s, void 0, IdentityAsync, f)); }; - function makeIx(i) { - var ix = function ix(s, j) { - return ix.v = j, s; - }; - ix.v = i; - return ix; - } - - function getNestedU(l, s, j, ix) { - for (var n = l.length, o; j < n; ++j) { - switch (typeof (o = l[j])) { - case 'string': - s = getProp(ix.v = o, s); - break; - case 'number': - s = getIndex(ix.v = o, s); - break; - case 'object': - s = getNestedU(o, s, 0, ix); - break; - default: - s = o(s, ix.v, Constant, ix); - } - }return s; - } - - var getU = /*#__PURE__*/(par(0, ef(reqOptic)))(function (l, s) { + var getAsU = /*#__PURE__*/(par(1, ef(reqOptic)))(function getAs(xi2y, l, s) { switch (typeof l) { case 'string': - return getProp(l, s); + return xi2y(getProp(l, s), l); case 'number': - return getIndex(l, s); + return xi2y(getIndex(l, s), l); case 'object': - for (var i = 0, n = l.length, o; i < n; ++i) { - switch (typeof (o = l[i])) { - case 'string': - s = getProp(o, s); - break; - case 'number': - s = getIndex(o, s); - break; - default: - return getNestedU(l, s, i, makeIx(l[i - 1])); - } - }return s; + { + var n = l.length; + for (var i = 0, o; i < n; ++i) { + switch (typeof (o = l[i])) { + case 'string': + s = getProp(o, s); + break; + case 'number': + s = getIndex(o, s); + break; + default: + return composed(i, l)(s, l[i - 1], Select, xi2y); + } + }return xi2y(s, l[n - 1]); + } default: - return l(s, void 0, Constant, id); + return xi2y !== id && l.length !== 4 ? xi2y(l(s, void 0), void 0) : l(s, void 0, Select, xi2y); } }); @@ -710,7 +701,7 @@ var r = void 0; for (var k in template) { var t = template[k]; - var v = I.isObject(t) ? getPick(t, x) : getU(t, x); + var v = I.isObject(t) ? getPick(t, x) : getAsU(id, t, x); if (void 0 !== v) { if (!r) r = {}; r[k] = v; @@ -1046,10 +1037,9 @@ }; }; - function zeroOp(y, i, C, xi2yC, x) { - var of = C.of; - return of ? of(y) : C.map(I.always(y), xi2yC(x, i)); - } + var zero = function zero(x, _i, C, _xi2yC) { + return C.of(x); + }; // @@ -1075,13 +1065,6 @@ // - var condOfDefault = /*#__PURE__*/I.always(zeroOp); - var condOfCase = function condOfCase(p, o, r) { - return function (y, j) { - return p(y, j) ? o : r(y, j); - }; - }; - // Auxiliary var seemsArrayLike = function seemsArrayLike(x) { @@ -1090,28 +1073,18 @@ // Internals - var Identity = /*#__PURE__*/(0, I.freeze)({ - map: I.applyU, - of: id, - ap: I.applyU, - chain: I.applyU - }); + var Identity = /*#__PURE__*/Monad(I.applyU, id, I.applyU, I.applyU); - var IdentityAsync = /*#__PURE__*/(0, I.freeze)({ - map: chainAsync, - ap: function ap(xyP, xP) { - return chainAsync(function (xP) { - return chainAsync(function (xyP) { - return xyP(xP); - }, xyP); - }, xP); - }, - of: id, - chain: chainAsync - }); + var IdentityAsync = /*#__PURE__*/Monad(chainAsync, id, function (xyP, xP) { + return chainAsync(function (xP) { + return chainAsync(function (xyP) { + return xyP(xP); + }, xyP); + }, xP); + }, chainAsync); - var Constant = /*#__PURE__*/(0, I.freeze)({ - map: I.sndU + var Select = /*#__PURE__*/ConstantWith(function (l, r) { + return void 0 !== l ? l : r; }); var toFunction = /*#__PURE__*/(par(0, ef(reqOptic)))(function toFunction(o) { @@ -1230,14 +1203,38 @@ }; })(function condOf(of) { of = toFunction(of); - var op = condOfDefault; - var n = arguments.length; - while (--n) { - var c = arguments[n]; - op = c.length === 1 ? I.always(toFunction(c[0])) : condOfCase(c[0], toFunction(c[1]), op); + + var n = arguments.length - 1; + if (!n) return zero; + + var def = arguments[n]; + if (def.length === 1) { + --n; + def = toFunction(def[0]); + } else { + def = zero; + } + + var ps = Array(n); + var os = Array(n + 1); + for (var i = 0; i < n; ++i) { + var c = arguments[i + 1]; + ps[i] = c[0]; + os[i] = toFunction(c[1]); } - return function condOf(x, i, C, xi2yC) { - return of(x, i, Constant, op)(x, i, C, xi2yC); + os[n] = def; + + return function condOf(x, i, F, xi2yF) { + var min = n; + of(x, i, Select, function (y, j) { + for (var _i3 = 0; _i3 < min; ++_i3) { + if (ps[_i3](y, j)) { + min = _i3; + if (_i3 === 0) return 0;else break; + } + } + }); + return os[min](x, i, F, xi2yF); }; }); @@ -1245,19 +1242,6 @@ return eitherU(toFunction(t), toFunction(e))(c); }); - var iftes = /*#__PURE__*/(function (fn$$1) { - return function iftes(_c, _t) { - warn(iftes, '`iftes` has been obsoleted. Use `ifElse` or `cond` instead. See CHANGELOG for details.'); - return fn$$1.apply(null, arguments); - }; - })(function iftes(_c, _t) { - var n = arguments.length; - var r = n & 1 ? toFunction(arguments[--n]) : zero; - while (0 <= (n -= 2)) { - r = eitherU(toFunction(arguments[n + 1]), r)(arguments[n]); - }return r; - }); - var orElse = /*#__PURE__*/I.curry(orElseU); // Querying @@ -1276,16 +1260,12 @@ return os.reduceRight(orElseU, zero); }; - var unless = /*#__PURE__*/eitherU(zeroOp, identity); + var unless = /*#__PURE__*/eitherU(zero, identity); - var when = /*#__PURE__*/eitherU(identity, zeroOp); + var when = /*#__PURE__*/eitherU(identity, zero); var optional = /*#__PURE__*/when(I.isDefined); - var zero = function zero(x, i, C, xi2yC) { - return zeroOp(x, i, C, xi2yC); - }; - // Indices var mapIx = function mapIx(ix2j) { @@ -1317,6 +1297,20 @@ // Debugging + function getLog(l, s) { + var _traverseU = traverseU(SelectLog, function (x) { + return { p: [x, consExcept], x: x, c: x }; + }, l, s), + p = _traverseU.p, + c = _traverseU.c; + + p = pushTo(p, ['%O']); + for (var i = 2; i < p.length; ++i) { + p[0] += ' <= %O'; + }console.log.apply(console, p); + return c; + } + function log() { var show = I.curry(function log(dir, x) { console.log.apply(console, copyToFrom([], 0, arguments, 0, arguments.length).concat([dir, x])); @@ -1325,16 +1319,6 @@ return isoU(show('get'), show('set')); } - var getLog = /*#__PURE__*/I.curry(function getLog(l, s) { - var _traverseU = traverseU(ConstantLog, getLogFn, l, s), - m = _traverseU.m, - p = _traverseU.p, - c = _traverseU.c; - - console.log.apply(console, pushTo(p, [m])); - return c; - }); - // Operations on transforms var transform = /*#__PURE__*/I.curry(function transform(o, s) { @@ -1370,14 +1354,14 @@ }; var modifyOp = function modifyOp(xi2y) { - return function modifyOp(x, i, C, xi2yC) { - return zeroOp(x = xi2y(x, i), i, C, xi2yC, x); + return function modifyOp(x, i, C, _xi2yC) { + return C.of(xi2y(x, i)); }; }; var setOp = function setOp(y) { - return function setOp(_x, i, C, xi2yC) { - return zeroOp(y, i, C, xi2yC, y); + return function setOp(_x, _i, C, _xi2yC) { + return C.of(y); }; }; @@ -1404,9 +1388,9 @@ // Traversals and combinators - var elems = /*#__PURE__*/(par(2, ef(reqApplicative('elems'))))(function elems(xs, i, A, xi2yA) { + function elems(xs, i, A, xi2yA) { return seemsArrayLike(xs) ? elemsI(xs, i, A, xi2yA) : A.of(xs); - }); + } var elemsTotal = function elemsTotal(xs, i, A, xi2yA) { return seemsArrayLike(xs) ? A === Identity ? mapPartialIndexU(xi2yA, xs, mapPartialIndexU) : A === Select ? selectInArrayLike(xi2yA, xs) : traversePartialIndex(A, xi2yA, xs, traversePartialIndex) : A.of(xs); @@ -1416,9 +1400,7 @@ var keys = /*#__PURE__*/setName( /*#__PURE__*/toFunction([keyed, elems, 0]), 'keys'); - var matches = /*#__PURE__*/(dep(function (re) { - return re.global ? res(par(2, ef(reqApplicative('matches', re)))) : id; - }))(function matches(re) { + function matches(re) { return function matches(x, _i, C, xi2yC) { if (I.isString(x)) { var map = C.map; @@ -1442,22 +1424,22 @@ }, xi2yC(m[0], reIndex(m))); } } - return zeroOp(x, void 0, C, xi2yC); + return C.of(x); }; - }); + } - var values = /*#__PURE__*/(par(2, ef(reqApplicative('values'))))( /*#__PURE__*/setName( /*#__PURE__*/branchOr1Level(identity, protoless0), 'values')); + var values = /*#__PURE__*/setName( /*#__PURE__*/branchOr1Level(identity, protoless0), 'values'); - var children = /*#__PURE__*/(par(2, ef(reqApplicative('children'))))(function children(x, i, C, xi2yC) { + function children(x, i, C, xi2yC) { return I.isArray(x) ? elemsI(x, i, C, xi2yC) : I.isObject(x) ? values(x, i, C, xi2yC) : C.of(x); - }); + } - var flatten = /*#__PURE__*/(par(2, ef(reqApplicative('flatten'))))(function flatten(x, i, C, xi2yC) { + function flatten(x, i, C, xi2yC) { var rec = function rec(x, i) { return I.isArray(x) ? elemsI(x, i, C, rec) : void 0 !== x ? xi2yC(x, i) : C.of(x); }; return rec(x, i); - }); + } function query() { var r = []; @@ -1484,7 +1466,7 @@ // Folds over traversals var all = /*#__PURE__*/I.curry(function all(xi2b, t, s) { - return !traverseU(Select, function (x, i) { + return !getAsU(function (x, i) { if (!xi2b(x, i)) return true; }, t, s); }); @@ -1492,7 +1474,7 @@ var and$1 = /*#__PURE__*/all(id); var any = /*#__PURE__*/I.curry(function any(xi2b, t, s) { - return !!traverseU(Select, function (x, i) { + return !!getAsU(function (x, i) { if (xi2b(x, i)) return true; }, t, s); }); @@ -1508,9 +1490,7 @@ var collect = /*#__PURE__*/collectAs(id); - var concatAs = /*#__PURE__*/mkTraverse(id, function concatAs(m) { - return ConcatOf(m.concat, m.empty()); - }); + var concatAs = /*#__PURE__*/mkTraverse(id, ConstantOf); var concat = /*#__PURE__*/concatAs(id); @@ -1567,16 +1547,24 @@ return c; }); + function get(l, s) { + return 1 < arguments.length ? getAsU(id, l, s) : function (s) { + return getAsU(id, l, s); + }; + } + + var getAs = /*#__PURE__*/I.curry(getAsU); + var isDefined = /*#__PURE__*/I.curry(function isDefined(t, s) { - return void 0 !== traverseU(Select, id, t, s); + return void 0 !== getAsU(id, t, s); }); var isEmpty = /*#__PURE__*/I.curry(function isEmpty(t, s) { - return !traverseU(Select, I.always(true), t, s); + return !getAsU(toTrue, t, s); }); var joinAs = /*#__PURE__*/mkTraverse(toStringPartial, /*#__PURE__*/(par(0, ef(reqString('`join` and `joinAs` expect a string delimiter'))))(function joinAs(d) { - return ConcatOf(function (x, y) { + return ConstantWith(function (x, y) { return void 0 !== x ? void 0 !== y ? x + d + y : x : y; }); })); @@ -1607,33 +1595,31 @@ var minimum = /*#__PURE__*/minimumBy(id); var none = /*#__PURE__*/I.curry(function none(xi2b, t, s) { - return !traverseU(Select, function (x, i) { + return !getAsU(function (x, i) { if (xi2b(x, i)) return true; }, t, s); }); var or$1 = /*#__PURE__*/any(id); - var productAs = /*#__PURE__*/traverse( /*#__PURE__*/ConcatOf(multiplyU, 1)); + var productAs = /*#__PURE__*/traverse( /*#__PURE__*/ConstantWith(multiplyU, 1)); var product = /*#__PURE__*/productAs( /*#__PURE__*/unto(1)); - var selectAs = /*#__PURE__*/traverse(Select); + var select = I.curry(function select(l, s) { + warn(select, '`select` has been obsoleted. Just use `get`. See CHANGELOG for details.'); + return get(l, s); + }); - var select = /*#__PURE__*/selectAs(id); + var selectAs = I.curry(function selectAs(f, l, s) { + warn(selectAs, '`selectAs` has been obsoleted. Just use `getAs`. See CHANGELOG for details.'); + return getAs(f, l, s); + }); var sumAs = /*#__PURE__*/traverse(Sum); var sum = /*#__PURE__*/sumAs(unto0); - // Operations on lenses - - function get(l, s) { - return 1 < arguments.length ? getU(l, s) : function (s) { - return getU(l, s); - }; - } - // Creating new lenses var lens = /*#__PURE__*/I.curry(lensU); @@ -1869,7 +1855,7 @@ var inverse = function inverse(iso) { return function (x, i, F, xi2yF) { return F.map(function (x) { - return getU(iso, x); + return getAsU(id, iso, x); }, xi2yF(setU(iso, x, void 0), i)); }; }; @@ -1903,10 +1889,10 @@ } n = xs.length; var j = 0; - for (var _i3 = 0; _i3 < n; ++_i3) { - var x = xs[_i3]; + for (var _i4 = 0; _i4 < n; ++_i4) { + var x = xs[_i4]; if (void 0 !== x) { - if (_i3 !== j) xs[j] = x; + if (_i4 !== j) xs[j] = x; ++j; } } @@ -1940,10 +1926,10 @@ var json = /*#__PURE__*/(res(function (iso) { return toFunction([iso, isoU(deepFreeze, id)]); }))(function json(options) { - var _ref2 = options || I.object0, - reviver = _ref2.reviver, - replacer = _ref2.replacer, - space = _ref2.space; + var _ref3 = options || I.object0, + reviver = _ref3.reviver, + replacer = _ref3.replacer, + space = _ref3.space; return isoU(expect(I.isString, function (text) { return JSON.parse(text, reviver); @@ -2024,7 +2010,7 @@ // Interop var pointer = function pointer(s) { - if (s[0] === '#') s = getU(uriComponent, s); + if (s[0] === '#') s = getAsU(id, uriComponent, s); var ts = s.split('/'); var n = ts.length; for (var i = 1; i < n; ++i) { @@ -2038,7 +2024,7 @@ exports.seemsArrayLike = seemsArrayLike; exports.Identity = Identity; exports.IdentityAsync = IdentityAsync; - exports.Constant = Constant; + exports.Select = Select; exports.toFunction = toFunction; exports.assign = assign; exports.modify = modify; @@ -2054,7 +2040,6 @@ exports.cond = cond; exports.condOf = condOf; exports.ifElse = ifElse; - exports.iftes = iftes; exports.orElse = orElse; exports.chain = chain; exports.choice = choice; @@ -2067,8 +2052,8 @@ exports.tieIx = tieIx; exports.joinIx = joinIx; exports.skipIx = skipIx; - exports.log = log; exports.getLog = getLog; + exports.log = log; exports.transform = transform; exports.transformAsync = transformAsync; exports.seq = seq; @@ -2105,6 +2090,8 @@ exports.foldr = foldr; exports.forEach = forEach; exports.forEachWith = forEachWith; + exports.get = get; + exports.getAs = getAs; exports.isDefined = isDefined; exports.isEmpty = isEmpty; exports.joinAs = joinAs; @@ -2119,11 +2106,10 @@ exports.or = or$1; exports.productAs = productAs; exports.product = product; - exports.selectAs = selectAs; exports.select = select; + exports.selectAs = selectAs; exports.sumAs = sumAs; exports.sum = sum; - exports.get = get; exports.lens = lens; exports.getter = getter; exports.setter = setter; diff --git a/dist/partial.lenses.min.js b/dist/partial.lenses.min.js index cf6043da..ccffffcd 100644 --- a/dist/partial.lenses.min.js +++ b/dist/partial.lenses.min.js @@ -1 +1 @@ -!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("infestines")):"function"==typeof define&&define.amd?define(["exports","infestines"],r):r(n.L={},n.I)}(this,function(n,b){"use strict";function e(n,r){for(var t=0,u=r.length;t>0&&0<=n||b.isString(n)},Jn=U({map:b.applyU,of:U,ap:b.applyU,chain:b.applyU}),Tn=U({map:N,ap:function(n,r){return N(function(r){return N(function(n){return n(r)},n)},r)},of:U,chain:N}),_n=U({map:b.sndU}),Gn=U(function(n){switch(typeof n){case"string":return en(n);case"number":return fn(n);case"object":return a(0,n);default:return 4===n.length?n:(e=n,S(function(n,r,t,u){return t.map(b.always(n),u(e(n,r),r))}))}var e}),Hn=b.curry(function(n,r,t){return vn([n,Ot(r)],r,t)}),Kn=b.curry(sn),Qn=b.curry(ln),Vn=b.curry(function(n,r){return vn(n,void 0,r)}),Xn=b.curry(vn),Yn=b.curry(K),Zn=function(e){return S(function(n,r,t,u){return Gn(e(n,r))(n,r,t,u)})},nr=U(function(){for(var n=arguments.length,r=ar;n--;){var t=arguments[n];r=t.length<2?Gn(t[0]):zn(Gn(t[1]),r)(t[0])}return r}),rr=U(function(e){e=Gn(e);for(var i=$n,n=arguments.length;--n;){var r=arguments[n];i=1===r.length?b.always(Gn(r[0])):Bn(r[0],Gn(r[1]),i)}return function(n,r,t,u){return e(n,r,_n,i)(n,r,t,u)}}),tr=b.curry(function(n,r,t){return zn(Gn(r),Gn(t))(n)}),ur=U(function(n,r){for(var t=arguments.length,u=1&t?Gn(arguments[--t]):ar;0<=(t-=2);)u=zn(Gn(arguments[t+1]),u)(arguments[t]);return u}),er=b.curry(Cn),ir=b.curry(function(t,n){return[n,Zn(function(n,r){return void 0!==n?t(n,r):ar})]}),or=zn(v,An),cr=zn(An,v),fr=cr(b.isDefined),ar=function(n,r,t,u){return v(n,r,t,u)},vr=b.curry(function(e,i){return i=Gn(i),S(function(n,t,r,u){return i(n,t,r,function(n,r){return u(n,e(r,t))})})}),sr=k(vr(function(n,r){return void 0!==r?void 0!==n?[r,n]:r:n})),lr=k(vr(b.sndU)),dr=b.curry(function(n,r){var t=K(Z,nn,n,r),u=t.c;return console.log.apply(console,X(t.p,[t.m])),u}),pr=b.curry(function(n,r){return sn(n,U,r)}),hr=b.curry(function(n,r){return ln(n,U,r)}),yr=U(function(){var n=arguments.length,r=ar;if(n)for(r=Gn(arguments[--n]);n;)r=Ln(Gn(arguments[--n]),r);return r}),gr=function(e){return function(n,r,t,u){return v(e,r,t,u,e)}},mr=gr(),br=U(b.curryN(2,function(r){return r=Gn(r),function(n){return function n(r,t){var u=O(null);for(var e in t){var i=t[e];u[e]=b.isObject(i)?n(r,i):Gn(i)}return wn(r,u)}(r,n)}})),jr=br(ar),Ar=U(function(n,r,t,u){return Fn(n)?Dn(n,0,t,u):t.of(n)}),Or=k(Gn([qn,Ar])),xr=k(Gn([qn,Ar,0])),wr=U(function(f){return function(r,n,t,u){if(b.isString(r)){var e=t.map;if(f.global){var i=[""];return i.input=r,i.index=0,T===t?function(n,r,t){for(;t=Nn(t,r);){var u=n(kn(t),Sn(t));if(void 0!==u)return u}}(u,f,i):e((c=r,function(n){for(var r="",t=0,u=function(n){for(var r=[];Rn!==n;)r.push(n[0],n[1]),n=n[2];return r}(n),e=u.length-2;-2!==e;e+=-2){var i=u[e];r+=c.slice(t,Sn(i));var o=u[e+1];void 0!==o&&(r+=o),t=En(i)}return r+c.slice(t)}),function(n,r,t,u,e,i){for(var o=t(Rn);i=Nn(i,e);)o=r(r(n(Rn,t(i)),o),u(kn(i),Sn(i)));return o}(e,t.ap,t.of,u,f,i))}var o=r.match(f);if(o)return e(function(n){return r.replace(f,void 0!==n?n:"")},u(o[0],Sn(o)))}var c;return v(r,void 0,t,u)}}),Ir=U(k(wn(An,w))),Ur=U(function(n,r,t,u){return b.isArray(n)?Dn(n,0,t,u):b.isObject(n)?Ir(n,r,t,u):t.of(n)}),kr=U(function(n,r,u,e){return function n(r,t){return b.isArray(r)?Dn(r,0,u,n):void 0!==r?e(r,t):u.of(r)}(n,r)}),Sr=function(i){return function(n,r,u,e){return function n(r,t){return i(r,t)?e(r,t):Ur(r,t,u,n)}(n,r)}},Er=Sr(function(n){return void 0!==n&&!b.isArray(n)&&!b.isObject(n)}),Nr=b.curry(function(t,n,r){return!K(T,function(n,r){if(!t(n,r))return!0},n,r)}),Rr=Nr(U),qr=b.curry(function(t,n,r){return!!K(T,function(n,r){if(t(n,r))return!0},n,r)}),Mr=(0,b.curry)(function(u,n,r){var e=[];return K(T,function(n,r){var t=u(n,r);void 0!==t&&e.push(t)},n,r),e}),Pr=Mr(U),zr=Q(U,function(n){return _(n.concat,n.empty())}),Cr=zr(U),Dr=b.curry(function(t,n,r){return K(G,function(n,r){return t(n,r)?1:0},n,r)}),Lr=Dr(b.isDefined),Wr=b.curry(function(e,n,r){var i=new Map;return K(T,function(n,r){var t=e(n,r),u=i.get(t);i.set(t,void 0!==u?u+1:1)},n,r),i}),$r=Wr(U),Br=b.curry(function(t,u,n,r){return K(T,function(n,r){u=t(u,n,r)},n,r),u}),Fr=b.curry(function(n,r,t,u){var e=[],i=[];K(T,function(n,r){i.push(n),e.push(r)},t,u);for(var o=i.length-1;0<=o;--o)r=n(r,i[o],e[o]);return r}),Jr=b.curry(function(t,n,r){return K(T,function(n,r){t(n,r)},n,r)}),Tr=b.curry(function(n,t,r,u){var e=n();return K(T,function(n,r){t(e,n,r)},r,u),e}),_r=b.curry(function(n,r){return void 0!==K(T,U,n,r)}),Gr=b.curry(function(n,r){return!K(T,b.always(!0),n,r)}),Hr=Q(R,U(function(t){return _(function(n,r){return void 0!==n?void 0!==r?n+t+r:n:r})})),Kr=Hr(U),Qr=H(j),Vr=Qr(U),Xr=b.curry(function(u,n,r){var e=0,i=0;return K(T,function(n,r){var t=u(n,r);void 0!==t&&(i+=1,e+=t)},n,r),e/i}),Yr=Xr(U),Zr=H(m),nt=Zr(U),rt=b.curry(function(t,n,r){return!K(T,function(n,r){if(t(n,r))return!0},n,r)}),tt=qr(U),ut=Yn(_(d,1)),et=ut(P(1)),it=Yn(T),ot=it(U),ct=Yn(G),ft=ct(z),at=b.curry(pn),vt=at(U),st=b.curry(function(n,r){return pn(n(r),Xn(r))}),lt=U(function(e){var i=P(e);return function(n,r,t,u){return t.map(i,u(void 0!==n?n:e,r))}}),dt=U(function(n){return wt(n,void 0)}),pt=function(e){return function(n,r,t,u){return u(void 0!==n?e(n,r):n,r)}},ht=function(e){return function(n,r,t,u){return t.map(function(n){return void 0!==n?e(n,r):n},u(n,r))}},yt=U(function(o){return function(n,r,t,u){var e=void 0,i=b.array0;return Fn(n)&&Un(o,n,e=[],i=[]),t.map(function(n){var r=n?n.length:0,t=i.length,u=r+t;return u===t?i:J(J(Array(u),0,n,0,r),r,i,0,t)},u(e,r))}}),gt=U,mt=Zn(function(n){return Fn(n)&&n.length?n.length-1:0}),bt=(0,b.curry)(function(f,a){return function(u,n,r,t){var e=Fn(u),i=e&&u.length,o=q(0,i,0,f),c=q(o,i,i,a);return r.map(function(n){var r=n?n.length:0,t=o+r;return J(J(J(Array(i-c+t),0,u,0,o),o,n,0,r),t,u,c,i)},t(e?J(Array(Math.max(0,c-o)),0,u,o,c):void 0,n))}}),jt=function(n){return b.isObject(n)?xt(Kn(Ir,Wn,n)):n},At=U,Ot=function(n){return r.apply(null,b.keys(n))},xt=U(function(e){return function(r,n,t,u){return t.map(function(n){return bn(e,n,r)},u(mn(e,r),n))}}),wt=b.curry(function(e,i){function o(n){return In(i,e,n)}return function(n,r,t,u){return t.map(o,u(In(e,i,n),r))}}),It=b.curry(hn),Ut=hn(C,C),kt=hn(L(Fn,U(function(n){for(var r=n.length,t=Array(r),u=0;u>0&&0<=n||b.isString(n)},Gn=K(b.applyU,k,b.applyU,b.applyU),Hn=K(q,k,function(n,r){return q(function(r){return q(function(n){return n(r)},n)},r)},q),Kn=Q(function(n,r){return void 0!==n?n:r}),Qn=k(function(n){switch(typeof n){case"string":return an(n);case"number":return ln(n);case"object":return a(0,n);default:return 4===n.length?n:(e=n,N(function(n,r,t,u){return t.map(b.always(n),u(e(n,r),r))}))}var e}),Vn=b.curry(function(n,r,t){return hn([n,bt(r)],r,t)}),Xn=b.curry(pn),Yn=b.curry(yn),Zn=b.curry(function(n,r){return hn(n,void 0,r)}),nr=b.curry(hn),rr=b.curry(Z),tr=function(e){return N(function(n,r,t,u){return Qn(e(n,r))(n,r,t,u)})},ur=k(function(){for(var n=arguments.length,r=$n;n--;){var t=arguments[n];r=t.length<2?Qn(t[0]):Cn(Qn(t[1]),r)(t[0])}return r}),er=k(function(i){i=Qn(i);var o=arguments.length-1;if(!o)return $n;var n=arguments[o];1===n.length?(--o,n=Qn(n[0])):n=$n;for(var c=Array(o),f=Array(o+1),r=0;r L.choices(optic, ...optics) ~> optic v11.10.0
  • L.choose((maybeValue, index) => optic) ~> optic v1.0.0
  • L.cond(...[(maybeValue, index) => testable, consequentOptic][, [alternativeOptic]]) ~> optic v13.1.0
  • -
  • L.condOf(lens, ...[(maybeValue, index) => testable, consequentOptic][, [alternativeOptic]]) ~> optic v13.5.0
  • +
  • L.condOf(traversal, ...[(maybeValue, index) => testable, consequentOptic][, [alternativeOptic]]) ~> optic v13.5.0
  • L.ifElse((maybeValue, index) => testable, optic, optic) ~> optic v13.1.0
  • -
  • L.iftes((maybeValue, index) => testable, consequentOptic, ...[, alternativeOptic]) ~> optic v11.14.0
  • L.orElse(backupOptic, primaryOptic) ~> optic v2.1.0
  • -
  • Querying -
  • Indices @@ -184,6 +174,15 @@

    L.values ~> traversal v7.3.0

  • +
  • Querying +
  • Folds over traversals @@ -223,10 +224,6 @@

    Lenses