partial.lenses
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -79,8 +79,8 @@ "use strict"; | ||
var L = function L() { | ||
for (var _len = arguments.length, ls = Array(_len), _key = 0; _key < _len; _key++) { | ||
ls[_key] = arguments[_key]; | ||
var L = function L(l) { | ||
for (var _len = arguments.length, ls = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
ls[_key - 1] = arguments[_key]; | ||
} | ||
return ls.length === 1 ? lift(ls[0]) : _ramda2.default.compose.apply(_ramda2.default, _toConsumableArray(ls.map(lift))); | ||
return ls.length === 0 ? lift(l) : _ramda2.default.compose.apply(_ramda2.default, [lift(l)].concat(_toConsumableArray(ls.map(lift)))); | ||
}; | ||
@@ -103,30 +103,28 @@ | ||
L.firstOf = function () { | ||
for (var _len2 = arguments.length, ls = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
ls[_key2] = arguments[_key2]; | ||
L.firstOf = function (l0) { | ||
for (var _len2 = arguments.length, ls = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
ls[_key2 - 1] = arguments[_key2]; | ||
} | ||
switch (ls.length) { | ||
case 0: | ||
throw new Error("firstOf called without arguments"); | ||
case 1: | ||
return lift(ls[0]); | ||
default: | ||
var choose = function choose(target, otherwise) { | ||
for (var i = 0, n = ls.length; i < n; ++i) { | ||
var l = ls[i]; | ||
var r = _ramda2.default.view(lift(l), target); | ||
if (undefined !== r) return otherwise ? l : r; | ||
} | ||
return otherwise; | ||
}; | ||
l0 = lift(l0); | ||
return function (toFunctor) { | ||
return function (target) { | ||
return _ramda2.default.map(function (focus) { | ||
return _ramda2.default.set(lift(choose(target, ls[0])), focus, target); | ||
}, toFunctor(choose(target))); | ||
}; | ||
}; | ||
} | ||
if (ls.length === 0) return l0; | ||
return function (toFunctor) { | ||
return function (target) { | ||
var l = l0; | ||
var r = _ramda2.default.view(l0, target); | ||
for (var i = 0; undefined === r && i < ls.length; ++i) { | ||
l = lift(ls[i]); | ||
r = _ramda2.default.view(l, target); | ||
} | ||
if (undefined === r) l = l0; | ||
return _ramda2.default.map(function (focus) { | ||
return _ramda2.default.set(l, focus, target); | ||
}, toFunctor(r)); | ||
}; | ||
}; | ||
}; | ||
@@ -199,2 +197,2 @@ | ||
exports.default = L; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9wYXJ0aWFsLmxlbnNlcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFJQSxJQUFNLFlBQVksU0FBWixTQUFZLENBQUMsQ0FBRCxFQUFJLENBQUosRUFBVTtBQUMxQixNQUFJLE1BQU0sU0FBTixJQUFtQixFQUFFLEtBQUssQ0FBTCxDQUFGLEVBQ3JCLE9BQU8sQ0FBUCxDQURGO0FBRUEsTUFBSSxhQUFKLENBSDBCO0FBSTFCLE9BQUssSUFBTSxDQUFOLElBQVcsQ0FBaEIsRUFBbUI7QUFDakIsUUFBSSxNQUFNLENBQU4sRUFBUztBQUNYLFVBQUksY0FBYyxDQUFkLEVBQ0YsSUFBSSxFQUFKLENBREY7QUFFQSxRQUFFLENBQUYsSUFBTyxFQUFFLENBQUYsQ0FBUCxDQUhXO0tBQWI7R0FERjtBQU9BLFNBQU8sQ0FBUCxDQVgwQjtDQUFWOztBQWNsQixJQUFNLFNBQVMsU0FBVCxNQUFTLENBQUMsQ0FBRCxFQUFJLENBQUosRUFBTyxDQUFQLEVBQWE7QUFDMUIsTUFBSSxNQUFNLFNBQU4sRUFDRiwyQkFBUyxHQUFJLEVBQWIsQ0FERjtBQUVBLE1BQUksS0FBSyxDQUFMLElBQVUsZ0JBQUUsTUFBRixDQUFTLENBQVQsRUFBWSxFQUFFLENBQUYsQ0FBWixDQUFWLEVBQ0YsT0FBTyxDQUFQLENBREY7QUFFQSxNQUFNLHdCQUFNLEdBQUksRUFBVixD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gIGlmICh4cyA9PT0gdW5kZWZpbmVkKVxuICAgICAgcmV0dXJuIFt4XVxuICAgIGNvbnN0IGkgPSB4cy5maW5kSW5kZXgocHJlZGljYXRlKVxuICAgIGlmIChpIDwgMClcbiAgICAgIHJldHVybiB4cy5jb25jYXQoW3hdKVxuICAgIGlmIChSLmVxdWFscyh4LCB4c1tpXSkpXG4gICAgICByZXR1cm4geHNcbiAgICByZXR1cm4geHMuc2xpY2UoMCwgaSkuY29uY2F0KFt4XSwgeHMuc2xpY2UoaSsxKSlcbiAgfVxufSlcblxuTC5pbmRleCA9IGkgPT4gUi5sZW5zKHhzID0+IHhzICYmIHhzW2ldLCAoeCwgeHMpID0+IHtcbiAgaWYgKHggPT09IHVuZGVmaW5lZCkge1xuICAgIGlmICh4cyA9PT0gdW5kZWZpbmVkKVxuICAgICAgcmV0dXJuIHVuZGVmaW5lZFxuICAgIGlmIChpIDwgeHMubGVuZ3RoKVxuICAgICAgcmV0dXJuIGRyb3BwZWQoeHMuc2xpY2UoMCwgaSkuY29uY2F0KHhzLnNsaWNlKGkrMSkpKVxuICAgIHJldHVybiB4c1xuICB9IGVsc2Uge1xuICAgIGlmICh4cyA9PT0gdW5kZWZpbmVkKVxuICAgICAgcmV0dXJuIEFycmF5KGkpLmNvbmNhdChbeF0pXG4gICAgaWYgKHhzLmxlbmd0aCA8PSBpKVxuICAgICAgcmV0dXJuIHhzLmNvbmNhdChBcnJheShpIC0geHMubGVuZ3RoKSwgW3hdKVxuICAgIGlmIChSLmVxdWFscyh4LCB4c1tpXSkpXG4gICAgICByZXR1cm4geHNcbiAgICByZXR1cm4geHMuc2xpY2UoMCwgaSkuY29uY2F0KFt4XSwgeHMuc2xpY2UoaSsxKSlcbiAgfVxufSlcblxuZXhwb3J0IGRlZmF1bHQgTFxuIl19 |
{ | ||
"name": "partial.lenses", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Ramda compatible lenses", | ||
@@ -5,0 +5,0 @@ "main": "lib/partial.lenses.js", |
@@ -116,4 +116,4 @@ [ [Examples](#examples) | [Reference](#reference) | [Background](#background) ] | ||
* `L(l1, ..., ln)` and `L.compose(l1, ..., ln)` both are the same as | ||
`R.compose(lift(l1), ..., lift(lN))` (see | ||
* `L(l0, ...ls)` and `L.compose(l0, ...ls)` both are the same as | ||
`R.compose(lift(l0), ...ls.map(lift))` (see | ||
[compose](http://ramdajs.com/0.19.0/docs/#compose)). | ||
@@ -129,3 +129,3 @@ * `L.lens(get, set)` is the same as `R.lens(get, set)` (see | ||
The `lift` operation is defined as | ||
The idempotent `lift` operation is defined as | ||
@@ -150,8 +150,8 @@ ```js | ||
#### L.firstOf(l1, ..., lN) | ||
#### L.firstOf(l0, ...ls) | ||
`L.firstOf(l1, ..., lN)` returns a partial lens that acts like the first of the | ||
given lenses whose view is not undefined on the given target. When the views of | ||
all of the given lenses are undefined, the returned lens acts like the first of | ||
the given lenses. | ||
`L.firstOf(l0, ...ls)` returns a partial lens that acts like the first of the | ||
given lenses, `l0, ...ls`, whose view is not undefined on the given target. | ||
When the views of all of the given lenses are undefined, the returned lens acts | ||
like `l0`. | ||
@@ -250,8 +250,8 @@ Note that `L.firstOf` is an associative operation, but there is no identity | ||
One might assume that `R.lensPath([p1, ..., pN])` is equivalent to | ||
`R.compose(R.lensProp(p1), ..., R.lensProp(pN))`, but that is not the case. | ||
One might assume that `R.lensPath([p0, ...ps])` is equivalent to | ||
`R.compose(R.lensProp(p0), ...ps.map(R.lensProp))`, but that is not the case. | ||
With partial lenses you can robustly compose a path lens from prop lenses | ||
`R.compose(L.prop(p1), ..., L.prop(pN))` or just use the shorthand notation | ||
`L(p1, ..., pN)`. | ||
`R.compose(L.prop(p0), ...ps.map(L.prop))` or just use the shorthand notation | ||
`L(p0, ...ps)`. | ||
@@ -258,0 +258,0 @@ ### Types |
@@ -56,3 +56,4 @@ import R from "ramda" | ||
const L = (...ls) => ls.length === 1 ? lift(ls[0]) : R.compose(...ls.map(lift)) | ||
const L = (l, ...ls) => | ||
ls.length === 0 ? lift(l) : R.compose(lift(l), ...ls.map(lift)) | ||
@@ -66,22 +67,21 @@ L.compose = L | ||
L.firstOf = (...ls) => { | ||
switch (ls.length) { | ||
case 0: | ||
throw new Error("firstOf called without arguments") | ||
case 1: | ||
return lift(ls[0]) | ||
default: | ||
const choose = (target, otherwise) => { | ||
for (let i=0, n=ls.length; i<n; ++i) { | ||
const l = ls[i] | ||
const r = R.view(lift(l), target) | ||
if (undefined !== r) | ||
return otherwise ? l : r | ||
} | ||
return otherwise | ||
L.firstOf = (l0, ...ls) => { | ||
l0 = lift(l0) | ||
if (ls.length === 0) | ||
return l0 | ||
return toFunctor => target => { | ||
let l = l0 | ||
let r = R.view(l0, target) | ||
for (let i=0; undefined === r && i<ls.length; ++i) { | ||
l = lift(ls[i]) | ||
r = R.view(l, target) | ||
} | ||
return toFunctor => target => | ||
R.map(focus => R.set(lift(choose(target, ls[0])), focus, target), | ||
toFunctor(choose(target))) | ||
if (undefined === r) | ||
l = l0 | ||
return R.map(focus => R.set(l, focus, target), toFunctor(r)) | ||
} | ||
@@ -88,0 +88,0 @@ } |
@@ -21,2 +21,35 @@ import R from "ramda" | ||
describe("arities", () => { | ||
testEq('L.compose.length', () => | ||
L.compose.length, 1) | ||
testEq('L.default.length', () => | ||
L.default.length, 1) | ||
testEq('L.define.length', () => | ||
L.define.length, 1) | ||
testEq('L.delete.length', () => | ||
L.delete.length, 2) | ||
testEq('L.find.length', () => | ||
L.find.length, 1) | ||
testEq('L.index.length', () => | ||
L.index.length, 1) | ||
testEq('L.length', () => | ||
L.length, 1) | ||
testEq('L.lens.length', () => | ||
L.lens.length, 2) | ||
testEq('L.normalize.length', () => | ||
L.normalize.length, 1) | ||
testEq('L.over.length', () => | ||
L.over.length, 3) | ||
testEq('L.prop.length', () => | ||
L.prop.length, 1) | ||
testEq('L.replace.length', () => | ||
L.replace.length, 2) | ||
testEq('L.required.length', () => | ||
L.required.length, 1) | ||
testEq('L.set.length', () => | ||
L.set.length, 3) | ||
testEq('L.view.length', () => | ||
L.view.length, 2) | ||
}) | ||
describe('L.find', () => { | ||
@@ -23,0 +56,0 @@ testEq('L.set(L.find(R.equals(2)), undefined, [,,2])', () => |
46062
442