partial.lenses
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -23,6 +23,10 @@ "use strict"; | ||
if (o === undefined || !(k in o)) return o; | ||
var r = {}; | ||
var r = undefined; | ||
for (var p in o) { | ||
if (p !== k) r[p] = o[p]; | ||
}return r; | ||
if (p !== k) { | ||
if (undefined === r) r = {}; | ||
r[p] = o[p]; | ||
} | ||
} | ||
return r; | ||
}; | ||
@@ -41,2 +45,8 @@ | ||
var dropped = function dropped(xs) { | ||
return Object.keys(xs).length === 0 ? undefined : xs; | ||
}; | ||
// | ||
var conserve = function conserve(f) { | ||
@@ -99,3 +109,3 @@ return function (n0, o) { | ||
if (i < 0) return xs; | ||
return xs.slice(0, i).concat(xs.slice(i + 1)); | ||
return dropped(xs.slice(0, i).concat(xs.slice(i + 1))); | ||
} else { | ||
@@ -117,3 +127,3 @@ if (xs === undefined) return [x]; | ||
if (xs === undefined) return undefined; | ||
if (i < xs.length) return xs.slice(0, i).concat(xs.slice(i + 1)); | ||
if (i < xs.length) return dropped(xs.slice(0, i).concat(xs.slice(i + 1))); | ||
return xs; | ||
@@ -130,2 +140,2 @@ } else { | ||
exports.default = L; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9wYXJ0aWFsLmxlbnNlcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUlBLElBQU0sWUFBWSxTQUFaLFNBQVksQ0FBQyxDQUFELEVBQUksQ0FBSixFQUFVO0FBQzFCLE1BQUksTUFBTSxTQUFOLElBQW1CLEVBQUUsS0FBSyxDQUFMLENBQUYsRUFDckIsT0FBTyxDQUFQLENBREY7QUFFQSxNQUFNLElBQUksRUFBSixDQUhvQjtBQUkxQixPQUFLLElBQU0sQ0FBTixJQUFXLENBQWhCO0FBQ0UsUUFBSSxNQUFNLENBQU4sRUFDRixFQUFFLENBQUYsSUFBTyxFQUFFL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bmVkKSB7XG4gICAgaWYgKHhzID09PSB1bmRlZmluZWQpXG4gICAgICByZXR1cm4gdW5kZWZpbmVkXG4gICAgaWYgKGkgPCB4cy5sZW5ndGgpXG4gICAgICByZXR1cm4gZHJvcHBlZCh4cy5zbGljZSgwLCBpKS5jb25jYXQoeHMuc2xpY2UoaSsxKSkpXG4gICAgcmV0dXJuIHhzXG4gIH0gZWxzZSB7XG4gICAgaWYgKHhzID09PSB1bmRlZmluZWQpXG4gICAgICByZXR1cm4gQXJyYXkoaSkuY29uY2F0KFt4XSlcbiAgICBpZiAoeHMubGVuZ3RoIDw9IGkpXG4gICAgICByZXR1cm4geHMuY29uY2F0KEFycmF5KGkgLSB4cy5sZW5ndGgpLCBbeF0pXG4gICAgaWYgKFIuZXF1YWxzKHgsIHhzW2ldKSlcbiAgICAgIHJldHVybiB4c1xuICAgIHJldHVybiB4cy5zbGljZSgwLCBpKS5jb25jYXQoW3hdLCB4cy5zbGljZShpKzEpKVxuICB9XG59KVxuXG5leHBvcnQgZGVmYXVsdCBMXG4iXX0= |
{ | ||
"name": "partial.lenses", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Ramda compatible lenses", | ||
@@ -5,0 +5,0 @@ "main": "lib/partial.lenses.js", |
127
README.md
[![npm version](https://badge.fury.io/js/partial.lenses.svg)](http://badge.fury.io/js/partial.lenses) | ||
This library provides a collection of Ramda compatible partial (dealing with | ||
`undefined` results) lenses. | ||
This library provides a collection of [Ramda](http://ramdajs.com/) compatible | ||
partial (dealing with `undefined` results) lenses. The intention is to make | ||
modification or editing of JSON data convenient and *compositional*. | ||
## Motivation | ||
Consider the following REPL session using Ramda 0.19.1: | ||
```js | ||
> R.set(R.lensPath(["x", "y"]), 1, {}) | ||
{ x: { y: 1 } } | ||
> R.set(R.compose(R.lensProp("x"), R.lensProp("y")), 1, {}) | ||
TypeError: Cannot read property 'y' of undefined | ||
> R.view(R.lensPath(["x", "y"]), {}) | ||
undefined | ||
> R.view(R.compose(R.lensProp("x"), R.lensProp("y")), {}) | ||
TypeError: Cannot read property 'y' of undefined | ||
> R.set(R.lensPath(["x", "y"]), undefined, {x: {y: 1}}) | ||
{ x: { y: undefined } } | ||
> R.set(R.compose(R.lensProp("x"), R.lensProp("y")), undefined, {x: {y: 1}}) | ||
{ x: { y: undefined } } | ||
``` | ||
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. | ||
## Usage | ||
The lenses and operations on lenses are accessed via the default import: | ||
```js | ||
import L from "partial.lenses" | ||
``` | ||
## Operations on lenses | ||
For convenience, you can access basic operations on lenses via the default | ||
import `L`: | ||
* `L.lens(get, set)` is the same as `R.lens(get, set)` (see [lens](http://ramdajs.com/0.19.0/docs/#lens)). | ||
* `L.over(lens, x2x, s)` is the same as `R.over(lens, x2x, s)` (see [over](http://ramdajs.com/0.19.0/docs/#over)). | ||
* `L.set(lens, x, s)` is the same as `R.set(lens, x, s)` (see [set](http://ramdajs.com/0.19.0/docs/#set)). | ||
* `L.view(lens, s)` is the same as `R.view(lens, s)` (see [view](http://ramdajs.com/0.19.0/docs/#view)). | ||
## Shorthand composition and lifting | ||
The default import, `L`, is also a shorthand function for lens composition and | ||
lifting. The semantics can be described as | ||
``` | ||
L(l1, ..., lN) === R.compose(lift(l1), ..., lift(lN)) | ||
``` | ||
where | ||
```js | ||
const lift = l => { | ||
switch (typeof l) { | ||
case "string": return L.prop(l) | ||
case "number": return L.index(l) | ||
default: return l | ||
} | ||
} | ||
``` | ||
## Lenses | ||
### L.prop(string) | ||
`L.prop(string)` is much like `R.lensProp(string)` (see | ||
[lensProp](http://ramdajs.com/0.19.0/docs/#lensProp)), but composes as a partial | ||
lens: | ||
* When viewing an undefined property or an undefined object, the result is | ||
undefined. | ||
* When setting property to undefined, the property is removed from the result. | ||
If the result would be an empty object, the whole result will be undefined. | ||
Examples: | ||
```js | ||
> L.set(L("x", "y"), undefined, {x: {y: 1}}) | ||
undefined | ||
> L.set(L("x", "y"), 2, {x: {y: 1}}) | ||
{ x: { y: 2 } } | ||
> L.set(L("x", "y"), undefined, {x: {y: 1}, z: 3}) | ||
{ z: 3 } | ||
> L.set(L("x", "y"), 2, {x: {y: 1}, z: 3}) | ||
{ x: { y: 2 }, z: 3 } | ||
> L.view(L("x", "y"), undefined) | ||
undefined | ||
``` | ||
### L.index(integer) | ||
`L.index(integer)` is like `R.lensIndex(integer)` (see | ||
[lensIndex](http://ramdajs.com/0.19.0/docs/#lensIndex)), but composes as a | ||
partial lens: | ||
* When viewing an undefined array index or an undefined array, the result is | ||
undefined. | ||
* When setting an array index to undefined, the element is removed from the | ||
resulting array, shifting all higher indices down by one. If the result would | ||
be an array without indices (ignoring length), the whole result will be | ||
undefined. | ||
### L.find(predicate) | ||
`L.find(predicate)` operates on arrays like `L.index`, but the index to be | ||
viewed is determined by finding the first element from the input array that | ||
matches the given unary predicate. When no matching element is found the effect | ||
is same as with `R.index` when the index set to the length of the array. | ||
### L.replace(inn, out) | ||
`L.replace(inn, out)`, when viewed, replaces the value `inn` with `out` and vice | ||
versa when set. Values are compared using `R.equals` (see | ||
[equals](http://ramdajs.com/0.19.0/docs/#equals)). | ||
Examples: | ||
```js | ||
> L.view(L(L.replace(undefined, {type: "title", text: ""}), "text"), undefined) | ||
"" | ||
> L.set(L(L.replace(undefined, {type: "title", text: ""}), "text"), "", {type: "title", text: "not empty"}) | ||
undefined | ||
``` |
@@ -8,6 +8,10 @@ import R from "ramda" | ||
return o | ||
const r = {} | ||
for (const p in o) | ||
if (p !== k) | ||
let r | ||
for (const p in o) { | ||
if (p !== k) { | ||
if (undefined === r) | ||
r = {} | ||
r[p] = o[p] | ||
} | ||
} | ||
return r | ||
@@ -30,2 +34,7 @@ } | ||
const dropped = xs => Object.keys(xs).length === 0 ? undefined : xs | ||
// | ||
const conserve = f => (n0, o) => { | ||
@@ -68,3 +77,3 @@ const n = f(n0, o) | ||
return xs | ||
return xs.slice(0, i).concat(xs.slice(i+1)) | ||
return dropped(xs.slice(0, i).concat(xs.slice(i+1))) | ||
} else { | ||
@@ -87,3 +96,3 @@ if (xs === undefined) | ||
if (i < xs.length) | ||
return xs.slice(0, i).concat(xs.slice(i+1)) | ||
return dropped(xs.slice(0, i).concat(xs.slice(i+1))) | ||
return xs | ||
@@ -90,0 +99,0 @@ } else { |
@@ -22,2 +22,4 @@ import R from "ramda" | ||
describe('L.find', () => { | ||
testEq('L.set(L.find(R.equals(2)), undefined, [,,2])', () => | ||
L.set(L.find(R.equals(2)), undefined, [,,2]), undefined) | ||
testEq('L.set(L.find(R.equals(2)), undefined, [1, 2, 3])', () => | ||
@@ -40,2 +42,4 @@ L.set(L.find(R.equals(2)), undefined, [1, 2, 3]), [1, 3]) | ||
describe('L.index', () => { | ||
testEq('L.set(L(1), undefined, [,,])', () => | ||
L.set(L(1), undefined, [,,]), undefined) | ||
testEq('L.set(L(1), 4, [1, 2, 3])', () => | ||
@@ -62,2 +66,4 @@ L.set(L(1), 4, [1, 2, 3]), [1, 4, 3]) | ||
describe('L.prop', () => { | ||
testEq('L.set(L("x"), undefined, {x: 1})', () => | ||
L.set(L("x"), undefined, {x: 1}), undefined) | ||
testEq('L.set(L("y"), undefined, {x: 1, y: 2})', () => | ||
@@ -64,0 +70,0 @@ L.set(L("y"), undefined, {x: 1, y: 2}), {x: 1}) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27267
282
128
0