partial.lenses
Advanced tools
Comparing version 1.4.1 to 2.0.0
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.lift = undefined; | ||
exports.props = exports.identity = exports.pick = exports.augment = exports.filter = exports.append = exports.index = exports.findWith = exports.find = exports.prop = exports.normalize = exports.define = exports.required = exports.defaults = exports.replace = exports.firstOf = exports.choose = exports.view = exports.set = exports.over = exports.lens = exports.removeAll = exports.remove = exports.compose = exports.lift = undefined; | ||
@@ -64,4 +64,4 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var conserve = function conserve(c0, c1) { | ||
return _ramda2.default.equals(c0, c1) ? c0 : c1; | ||
var conserve = function conserve(c1, c0) { | ||
return _ramda2.default.equals(c1, c0) ? c0 : c1; | ||
}; | ||
@@ -71,3 +71,3 @@ | ||
return function (y, c0) { | ||
return conserve(c0, f(y, c0)); | ||
return conserve(f(y, c0), c0); | ||
}; | ||
@@ -81,5 +81,5 @@ }; | ||
case "string": | ||
return L.prop(l); | ||
return prop(l); | ||
case "number": | ||
return L.index(l); | ||
return index(l); | ||
default: | ||
@@ -90,31 +90,32 @@ return l; | ||
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]; | ||
var compose = exports.compose = function compose() { | ||
for (var _len = arguments.length, ls = Array(_len), _key = 0; _key < _len; _key++) { | ||
ls[_key] = arguments[_key]; | ||
} | ||
return ls.length === 0 ? lift(l) : _ramda2.default.compose.apply(_ramda2.default, [lift(l)].concat(_toConsumableArray(ls.map(lift)))); | ||
return ls.length === 0 ? identity : ls.length === 1 ? lift(ls[0]) : _ramda2.default.compose.apply(_ramda2.default, _toConsumableArray(ls.map(lift))); | ||
}; | ||
L.compose = L; | ||
L.delete = _ramda2.default.curry(function (l, s) { | ||
var remove = exports.remove = _ramda2.default.curry(function (l, s) { | ||
return _ramda2.default.set(lift(l), undefined, s); | ||
}); | ||
L.deleteAll = _ramda2.default.curry(function (lens, data) { | ||
while (L.view(lens, data) !== undefined) { | ||
data = L.delete(lens, data); | ||
var removeAll = exports.removeAll = _ramda2.default.curry(function (lens, data) { | ||
while (view(lens, data) !== undefined) { | ||
data = remove(lens, data); | ||
}return data; | ||
}); | ||
L.lens = _ramda2.default.lens; | ||
L.over = _ramda2.default.curry(function (l, x2x, s) { | ||
var lens = exports.lens = _ramda2.default.lens; | ||
var over = exports.over = _ramda2.default.curry(function (l, x2x, s) { | ||
return _ramda2.default.over(lift(l), x2x, s); | ||
}); | ||
L.set = _ramda2.default.curry(function (l, x, s) { | ||
var set = exports.set = _ramda2.default.curry(function (l, x, s) { | ||
return _ramda2.default.set(lift(l), x, s); | ||
}); | ||
L.view = _ramda2.default.curry(function (l, s) { | ||
var view = exports.view = _ramda2.default.curry(function (l, s) { | ||
return _ramda2.default.view(lift(l), s); | ||
}); | ||
L.choose = function (x2yL) { | ||
var choose = exports.choose = function choose(x2yL) { | ||
return function (toFunctor) { | ||
@@ -130,3 +131,3 @@ return function (target) { | ||
L.firstOf = function (l) { | ||
var firstOf = exports.firstOf = function firstOf(l) { | ||
for (var _len2 = arguments.length, ls = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
@@ -136,6 +137,6 @@ ls[_key2 - 1] = arguments[_key2]; | ||
return L.choose(function (x) { | ||
return choose(function (x) { | ||
var lls = [l].concat(ls); | ||
return lls[Math.max(0, lls.findIndex(function (l) { | ||
return L.view(l, x) !== undefined; | ||
return view(l, x) !== undefined; | ||
}))]; | ||
@@ -145,3 +146,3 @@ }); | ||
L.replace = _ramda2.default.curry(function (inn, out) { | ||
var replace = exports.replace = _ramda2.default.curry(function (inn, out) { | ||
return _ramda2.default.lens(function (x) { | ||
@@ -154,15 +155,15 @@ return _ramda2.default.equals(x, inn) ? out : x; | ||
L.default = L.replace(undefined); | ||
L.required = function (inn) { | ||
return L.replace(inn, undefined); | ||
var defaults = exports.defaults = replace(undefined); | ||
var required = exports.required = function required(inn) { | ||
return replace(inn, undefined); | ||
}; | ||
L.define = function (v) { | ||
return _ramda2.default.compose(L.required(v), L.default(v)); | ||
var define = exports.define = function define(v) { | ||
return _ramda2.default.compose(required(v), defaults(v)); | ||
}; | ||
L.normalize = function (transform) { | ||
var normalize = exports.normalize = function normalize(transform) { | ||
return _ramda2.default.lens(toPartial(transform), toConserve(toPartial(transform))); | ||
}; | ||
L.prop = function (k) { | ||
var prop = exports.prop = function prop(k) { | ||
return _ramda2.default.lens(function (o) { | ||
@@ -175,11 +176,11 @@ return o && o[k]; | ||
L.find = function (predicate) { | ||
return L.choose(function (xs) { | ||
if (xs === undefined) return L.append; | ||
var find = exports.find = function find(predicate) { | ||
return choose(function (xs) { | ||
if (xs === undefined) return append; | ||
var i = xs.findIndex(predicate); | ||
return i < 0 ? L.append : i; | ||
return i < 0 ? append : i; | ||
}); | ||
}; | ||
L.findWith = function (l) { | ||
var findWith = exports.findWith = function findWith(l) { | ||
for (var _len3 = arguments.length, ls = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
@@ -189,4 +190,4 @@ ls[_key3 - 1] = arguments[_key3]; | ||
var lls = L.apply(undefined, [l].concat(ls)); | ||
return L(L.find(function (x) { | ||
var lls = compose.apply(undefined, [l].concat(ls)); | ||
return compose(find(function (x) { | ||
return _ramda2.default.view(lls, x) !== undefined; | ||
@@ -196,3 +197,3 @@ }), lls); | ||
L.index = function (i) { | ||
var index = exports.index = function index(i) { | ||
return _ramda2.default.lens(function (xs) { | ||
@@ -214,15 +215,15 @@ return xs && xs[i]; | ||
L.append = _ramda2.default.lens(function () {}, function (x, xs) { | ||
var append = exports.append = _ramda2.default.lens(function () {}, function (x, xs) { | ||
return x === undefined ? xs : xs === undefined ? [x] : xs.concat([x]); | ||
}); | ||
L.filter = function (p) { | ||
var filter = exports.filter = function filter(p) { | ||
return _ramda2.default.lens(function (xs) { | ||
return xs && xs.filter(p); | ||
}, function (ys, xs) { | ||
return conserve(xs, dropped(_ramda2.default.concat(ys || [], (xs || []).filter(_ramda2.default.complement(p))))); | ||
return conserve(dropped(_ramda2.default.concat(ys || [], (xs || []).filter(_ramda2.default.complement(p)))), xs); | ||
}); | ||
}; | ||
L.augment = function (template) { | ||
var augment = exports.augment = function augment(template) { | ||
return _ramda2.default.lens(toPartial(function (x) { | ||
@@ -247,7 +248,7 @@ var z = _extends({}, x); | ||
L.pick = function (template) { | ||
var pick = exports.pick = function pick(template) { | ||
return _ramda2.default.lens(function (c) { | ||
var r = void 0; | ||
for (var k in template) { | ||
var v = L.view(template[k], c); | ||
var v = view(template[k], c); | ||
if (v !== undefined) { | ||
@@ -265,3 +266,3 @@ if (r === undefined) r = {}; | ||
for (var k in template) { | ||
c = L.set(template[k], o[k], c); | ||
c = set(template[k], o[k], c); | ||
}return c; | ||
@@ -271,5 +272,5 @@ }); | ||
L.identity = _ramda2.default.lens(_ramda2.default.identity, _ramda2.default.identity); | ||
var identity = exports.identity = _ramda2.default.lens(_ramda2.default.identity, conserve); | ||
L.props = function (k) { | ||
var props = exports.props = function props(k) { | ||
for (var _len4 = arguments.length, ks = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
@@ -280,6 +281,6 @@ ks[_key4 - 1] = arguments[_key4]; | ||
var kks = [k].concat(ks); | ||
return L.pick(_ramda2.default.zipObj(kks, kks)); | ||
return pick(_ramda2.default.zipObj(kks, kks)); | ||
}; | ||
exports.default = L; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9wYXJ0aWFsLmxlbnNlcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7OztBQUFBOzs7Ozs7Ozs7Ozs7QUFJQSxJQ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hzICYmIHhzLmZpbHRlcihwKSwgKHlzLCB4cykgPT5cbiAgY29uc2VydmUoeHMsIGRyb3BwZWQoUi5jb25jYXQoeXMgfHwgW10sICh4cyB8fCBbXSkuZmlsdGVyKFIuY29tcGxlbWVudChwKSkpKSkpXG5cbkwuYXVnbWVudCA9IHRlbXBsYXRlID0+IFIubGVucyhcbiAgdG9QYXJ0aWFsKHggPT4ge1xuICAgIGNvbnN0IHogPSB7Li4ueH1cbiAgICBmb3IgKGNvbnN0IGsgaW4gdGVtcGxhdGUpXG4gICAgICB6W2tdID0gdGVtcGxhdGVba10oeClcbiAgICByZXR1cm4gelxuICB9KSxcbiAgdG9Db25zZXJ2ZSgoeSwgYykgPT4ge1xuICAgIGlmICh5ID09PSB1bmRlZmluZWQpXG4gICAgICByZXR1cm4gdW5kZWZpbmVkXG4gICAgbGV0IHpcbiAgICBjb25zdCBzZXQgPSAoaywgdikgPT4ge1xuICAgICAgaWYgKHVuZGVmaW5lZCA9PT0geilcbiAgICAgICAgeiA9IHt9XG4gICAgICB6W2tdID0gdlxuICAgIH1cbiAgICBmb3IgKGNvbnN0IGsgaW4geSkge1xuICAgICAgaWYgKCEoayBpbiB0ZW1wbGF0ZSkpXG4gICAgICAgIHNldChrLCB5W2tdKVxuICAgICAgZWxzZVxuICAgICAgICBpZiAoayBpbiBjKVxuICAgICAgICAgIHNldChrLCBjW2tdKVxuICAgIH1cbiAgICByZXR1cm4gelxuICB9KSlcblxuTC5waWNrID0gdGVtcGxhdGUgPT4gUi5sZW5zKFxuICBjID0+IHtcbiAgICBsZXQgclxuICAgIGZvciAoY29uc3QgayBpbiB0ZW1wbGF0ZSkge1xuICAgICAgY29uc3QgdiA9IEwudmlldyh0ZW1wbGF0ZVtrXSwgYylcbiAgICAgIGlmICh2ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgaWYgKHIgPT09IHVuZGVmaW5lZClcbiAgICAgICAgICByID0ge31cbiAgICAgICAgcltrXSA9IHZcbiAgICAgIH1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c3QgayBpbiB0ZW1wbGF0ZSlcbiAgICAgIHpba10gPSB0ZW1wbGF0ZVtrXSh4KVxuICAgIHJldHVybiB6XG4gIH0pLFxuICB0b0NvbnNlcnZlKCh5LCBjKSA9PiB7XG4gICAgaWYgKHkgPT09IHVuZGVmaW5lZClcbiAgICAgIHJldHVybiB1bmRlZmluZWRcbiAgICBsZXQgelxuICAgIGNvbnN0IHNldCA9IChrLCB2KSA9PiB7XG4gICAgICBpZiAodW5kZWZpbmVkID09PSB6KVxuICAgICAgICB6ID0ge31cbiAgICAgIHpba10gPSB2XG4gICAgfVxuICAgIGZvciAoY29uc3QgayBpbiB5KSB7XG4gICAgICBpZiAoIShrIGluIHRlbXBsYXRlKSlcbiAgICAgICAgc2V0KGssIHlba10pXG4gICAgICBlbHNlXG4gICAgICAgIGlmIChrIGluIGMpXG4gICAgICAgICAgc2V0KGssIGNba10pXG4gICAgfVxuICAgIHJldHVybiB6XG4gIH0pKVxuXG5leHBvcnQgY29uc3QgcGljayA9IHRlbXBsYXRlID0+IFIubGVucyhcbiAgYyA9PiB7XG4gICAgbGV0IHJcbiAgICBmb3IgKGNvbnN0IGsgaW4gdGVtcGxhdGUpIHtcbiAgICAgIGNvbnN0IHYgPSB2aWV3KHRlbXBsYXRlW2tdLCBjKVxuICAgICAgaWYgKHYgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICBpZiAociA9PT0gdW5kZWZpbmVkKVxuICAgICAgICAgIHIgPSB7fVxuICAgICAgICByW2tdID0gdlxuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gclxuICB9LFxuICAobyA9IGVtcHR5LCBjSW4pID0+IHtcbiAgICBsZXQgYyA9IGNJblxuICAgIGZvciAoY29uc3QgayBpbiB0ZW1wbGF0ZSlcbiAgICAgIGMgPSBzZXQodGVtcGxhdGVba10sIG9ba10sIGMpXG4gICAgcmV0dXJuIGNcbiAgfSlcblxuZXhwb3J0IGNvbnN0IGlkZW50aXR5ID0gUi5sZW5zKFIuaWRlbnRpdHksIGNvbnNlcnZlKVxuXG5leHBvcnQgY29uc3QgcHJvcHMgPSAoaywgLi4ua3MpID0+IHtcbiAgY29uc3Qga2tzID0gW2ssIC4uLmtzXVxuICByZXR1cm4gcGljayhSLnppcE9iaihra3MsIGtrcykpXG59XG5cbmV4cG9ydCBkZWZhdWx0IGNvbXBvc2VcbiJdfQ== |
{ | ||
"name": "partial.lenses", | ||
"version": "1.4.1", | ||
"version": "2.0.0", | ||
"description": "Ramda compatible partial lenses", | ||
@@ -28,11 +28,11 @@ "main": "lib/partial.lenses.js", | ||
"dependencies": { | ||
"ramda": "^0.19.1" | ||
"ramda": "^0.20.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.6.5", | ||
"babel-eslint": "^5.0.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.7.0", | ||
"babel-eslint": "^6.0.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.7.4", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-2": "^6.5.0", | ||
"eslint": "2.2.x", | ||
"eslint": "2.5.x", | ||
"mocha": "^2.4.5", | ||
@@ -39,0 +39,0 @@ "nyc": "^6.1.1" |
482
README.md
[ [Tutorial](#tutorial) | [Reference](#reference) | [Background](#background) ] | ||
Lenses are a convenient abstraction for performing updates on individual | ||
elements of immutable data structures. This library provides a collection of | ||
[Ramda](http://ramdajs.com/) compatible *partial* lenses. While an ordinary | ||
lens can be used to view and update an existing part of a data structure, a | ||
partial lens can *view* optional data, *insert* new data, *update* existing data | ||
and *delete* existing data and can provide *default* values and maintain | ||
Lenses are primarily a convenient abstraction for performing updates on | ||
individual elements of immutable data structures. This library provides a | ||
collection of [Ramda](http://ramdajs.com/) compatible *partial* lenses. While | ||
an ordinary lens can be used to view and update an existing part of a data | ||
structure, a partial lens can *view* optional data, *insert* new data, *update* | ||
existing data and *remove* existing data and can provide *defaults* and maintain | ||
*required* data structure parts. | ||
@@ -14,3 +14,3 @@ | ||
it returns `undefined`. When a part is missing, setting it to a defined value | ||
inserts the new part. Setting an existing part to `undefined` deletes it. | ||
inserts the new part. Setting an existing part to `undefined` removes it. | ||
Partial lenses are defined in such a way that operations compose and one can | ||
@@ -33,3 +33,3 @@ conveniently and robustly operate on deeply nested data structures. | ||
```js | ||
import L from "partial.lenses" | ||
import * as L from "partial.lenses" | ||
import R from "ramda" | ||
@@ -46,5 +46,5 @@ ``` | ||
L.find(R.whereEq({language})), | ||
L.default({language}), | ||
L.defaults({language}), | ||
L.prop("text"), | ||
L.default("")) | ||
L.defaults("")) | ||
``` | ||
@@ -62,6 +62,6 @@ | ||
```js | ||
> L.view(textIn("sv"), data) | ||
"Rubrik" | ||
> L.view(textIn("en"), data) | ||
"Title" | ||
L.view(textIn("sv"), data) | ||
// "Rubrik" | ||
L.view(textIn("en"), data) | ||
// "Title" | ||
``` | ||
@@ -73,13 +73,13 @@ | ||
```js | ||
> L.view(textIn("fi"), data) | ||
"" | ||
L.view(textIn("fi"), data) | ||
// "" | ||
``` | ||
We get this default, rather than undefined, thanks to the last part, | ||
`L.default("")`, of our lens composition. We get the default even if we query | ||
`L.defaults("")`, of our lens composition. We get the default even if we query | ||
from `undefined`: | ||
```js | ||
> L.view(textIn("fi"), undefined) | ||
"" | ||
L.view(textIn("fi"), undefined) | ||
// "" | ||
``` | ||
@@ -94,5 +94,5 @@ | ||
```js | ||
> L.set(textIn("en"), "The title", data) | ||
{ contents: [ { language: "en", text: "The title" }, | ||
{ language: "sv", text: "Rubrik" } ] } | ||
L.set(textIn("en"), "The title", data) | ||
// { contents: [ { language: "en", text: "The title" }, | ||
// { language: "sv", text: "Rubrik" } ] } | ||
``` | ||
@@ -105,6 +105,6 @@ | ||
```js | ||
> L.set(textIn("fi"), "Otsikko", data) | ||
{ contents: [ { language: "en", text: "Title" }, | ||
{ language: "fi", text: "Otsikko" }, | ||
{ language: "sv", text: "Rubrik" } ] } | ||
L.set(textIn("fi"), "Otsikko", data) | ||
// { contents: [ { language: "en", text: "Title" }, | ||
// { language: "fi", text: "Otsikko" }, | ||
// { language: "sv", text: "Rubrik" } ] } | ||
``` | ||
@@ -116,9 +116,9 @@ | ||
### Deleting data | ||
### Removing data | ||
Finally, we can use the same partial lens to delete texts: | ||
Finally, we can use the same partial lens to remove texts: | ||
```js | ||
> L.set(textIn("sv"), undefined, data) | ||
{ contents: [ { language: "en", text: "Title" } ] } | ||
L.set(textIn("sv"), undefined, data) | ||
// { contents: [ { language: "en", text: "Title" } ] } | ||
``` | ||
@@ -128,25 +128,25 @@ | ||
whole object vanish, rather than just the `text` property, is the | ||
`L.default({language})` part of our lens composition. A `L.default(value)` lens | ||
`L.defaults({language})` part of our lens composition. A `L.defaults(value)` lens | ||
works *symmetrically*. When set with `value`, the result is `undefined`, which | ||
means that the focus of the lens is to be deleted. | ||
means that the focus of the lens is to be removed. | ||
If we delete all of the texts, we get the required value: | ||
If we remove all of the texts, we get the required value: | ||
```js | ||
> R.pipe(L.set(textIn("sv"), undefined), | ||
L.set(textIn("en"), undefined))(data) | ||
{ contents: [] } | ||
R.pipe(L.set(textIn("sv"), undefined), | ||
L.set(textIn("en"), undefined))(data) | ||
// { contents: [] } | ||
``` | ||
The `contents` property is not removed thanks to the `L.required([])` part of | ||
our lens composition. `L.required` is the dual of `L.default`. `L.default` | ||
our lens composition. `L.required` is the dual of `L.defaults`. `L.defaults` | ||
replaces undefined values when viewed and `L.required` replaces undefined values | ||
when set. | ||
Note that unless required and default values are explicitly specified as part of | ||
the lens, they will both be undefined. | ||
Note that unless defaults and required values are explicitly specified as part | ||
of the lens, they will both be undefined. | ||
### Exercise | ||
Take out one (or more) `L.required(...)`, `L.normalize(...)` or `L.default(...)` | ||
Take out one (or more) `L.required(...)`, `L.normalize(...)` or `L.defaults(...)` | ||
part(s) from the lens composition and try to predict what happens when you rerun | ||
@@ -160,5 +160,5 @@ the examples with the modified lens composition. Verify your reasoning by | ||
library supports. In particular, | ||
* `L.compose(...)` can be abbreviated as `L(...)`, | ||
* `L.compose(...)` can be abbreviated to use the default import, e.g. `P(...)`, | ||
* `L.prop(string)` can be abbreviated as `string`, and | ||
* `L.set(l, undefined, s)` can be abbreviated as `L.delete(l, s)`. | ||
* `L.set(l, undefined, s)` can be abbreviated as `L.remove(l, s)`. | ||
@@ -177,5 +177,5 @@ ### Systematic decomposition | ||
L.find(R.whereEq({language})), | ||
L.default({language}), | ||
L.defaults({language}), | ||
L.prop("text"), | ||
L.default("")) | ||
L.defaults("")) | ||
``` | ||
@@ -195,3 +195,3 @@ | ||
data: { | ||
contents: L("contents", | ||
contents: P("contents", | ||
L.required([]), | ||
@@ -201,7 +201,7 @@ L.normalize(R.sortBy(R.prop("language")))) | ||
contents: { | ||
contentIn: language => L(L.find(R.whereEq({language})), | ||
L.default({language})) | ||
contentIn: language => P(L.find(R.whereEq({language})), | ||
L.defaults({language})) | ||
}, | ||
content: { | ||
text: L("text", L.default("")) | ||
text: P("text", L.defaults("")) | ||
} | ||
@@ -214,3 +214,3 @@ } | ||
```js | ||
const textIn = language => L(M.data.contents, | ||
const textIn = language => P(M.data.contents, | ||
M.contents.contentIn(language), | ||
@@ -242,8 +242,8 @@ M.content.text) | ||
const search = key => | ||
L(L.default({key}), | ||
L.choose(n => key < n.key ? L("smaller", search(key)) : | ||
n.key < key ? L("greater", search(key)) : | ||
P(L.defaults({key}), | ||
L.choose(n => key < n.key ? P("smaller", search(key)) : | ||
n.key < key ? P("greater", search(key)) : | ||
L.identity)) | ||
const valueOf = key => L(search(key), "value") | ||
const valueOf = key => P(search(key), "value") | ||
``` | ||
@@ -255,22 +255,23 @@ | ||
```js | ||
> const t = R.reduce((tree, item) => L.set(valueOf(item.key), item.value, tree), | ||
undefined, | ||
[{key: "c", value: 1}, | ||
{key: "a", value: 2}, | ||
{key: "b", value: 3}]) | ||
> t | ||
{ smaller: { greater: { value: 3, key: 'b' }, value: 2, key: 'a' }, | ||
value: 1, | ||
key: 'c' } | ||
const t = R.reduce( | ||
(tree, {key, value}) => L.set(valueOf(key), value, tree), | ||
undefined, | ||
[{key: "c", value: 1}, | ||
{key: "a", value: 2}, | ||
{key: "b", value: 3}]) | ||
t | ||
// { smaller: { greater: { value: 3, key: 'b' }, value: 2, key: 'a' }, | ||
// value: 1, | ||
// key: 'c' } | ||
``` | ||
However, the above `search` lens constructor does not maintain the BST | ||
structure when values are being deleted: | ||
structure when values are being removed: | ||
```js | ||
> L.delete(valueOf('c'), t) | ||
{ smaller: { greater: { value: 3, key: 'b' }, | ||
value: 2, | ||
key: 'a' }, | ||
key: 'c' } | ||
L.remove(valueOf('c'), t) | ||
// { smaller: { greater: { value: 3, key: 'b' }, | ||
// value: 2, | ||
// key: 'a' }, | ||
// key: 'c' } | ||
``` | ||
@@ -284,3 +285,3 @@ | ||
const search = key => | ||
L(L.normalize(n => | ||
P(L.normalize(n => | ||
undefined !== n.value ? n : | ||
@@ -290,18 +291,21 @@ n.smaller && !n.greater ? n.smaller : | ||
L.set(search(n.smaller.key), n.smaller, n.greater)), | ||
L.default({key}), | ||
L.choose(n => key < n.key ? L("smaller", search(key)) : | ||
n.key < key ? L("greater", search(key)) : | ||
L.defaults({key}), | ||
L.choose(n => key < n.key ? P("smaller", search(key)) : | ||
n.key < key ? P("greater", search(key)) : | ||
L.identity)) | ||
``` | ||
Now we can also delete values from a binary tree: | ||
Now we can also remove values from a binary tree: | ||
```js | ||
> L.delete(valueOf('c'), t) | ||
{ greater: { value: 3, key: 'b' }, value: 2, key: 'a' } | ||
L.remove(valueOf('c'), t) | ||
// { greater: { value: 3, key: 'b' }, value: 2, key: 'a' } | ||
``` | ||
As an exercise you could improve the normalization to maintain some balance | ||
condition such as AVL. Another worthy exercise would be to make it so that the | ||
empty binary tree is `null` rather than `undefined`. | ||
As an exercise, you could improve the normalization to better maintain balance. | ||
Perhaps you might even enhance it to maintain a balance condition such as | ||
[AVL](https://en.wikipedia.org/wiki/AVL_tree) or | ||
[Red-Black](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree). Another | ||
worthy exercise would be to make it so that the empty binary tree is `null` | ||
rather than `undefined`. | ||
@@ -315,31 +319,15 @@ ## Reference | ||
```js | ||
import L from "partial.lenses" | ||
import P, * as L from "partial.lenses" | ||
``` | ||
Use of the default import, `P`, is optional and is an alias for `L.compose`. | ||
### Operations on lenses | ||
You can access basic operations on lenses via the default import `L`: | ||
In alphabetical order. | ||
#### [`L.compose(l, ...ls)`](#lcomposel-ls "L.compose :: (PLens s s1, ...PLens sN a) -> PLens s a") | ||
`L(l, ...ls)` and `L.compose(l, ...ls)` both are the same as `R.compose(lift(l), | ||
...ls.map(lift))` (see [compose](http://ramdajs.com/0.19.0/docs/#compose)) and | ||
compose a lens from a path of lenses. | ||
For example: | ||
```js | ||
> L.view(L("a", 1), {a: ["b", "c"]}) | ||
"c" | ||
``` | ||
#### [`L.lens(get, set)`](#llensget-set "L.lens :: (Maybe s -> Maybe a) -> (Maybe a -> Maybe s -> Maybe s) -> PLens s a") | ||
`L.lens(get, set)` is the same as `R.lens(get, set)` (see | ||
[lens](http://ramdajs.com/0.19.0/docs/#lens)) and creates a new primitive lens. | ||
#### [`L.over(l, x2x, s)`](#loverl-x2x-s "L.over :: PLens s a -> (Maybe a -> Maybe a) -> Maybe s -> Maybe s") | ||
`L.over(l, x2x, s)` is the same as `R.over(lift(l), x2x, s)` (see | ||
[over](http://ramdajs.com/0.19.0/docs/#over)) and allows one to map over the | ||
[over](http://ramdajs.com/0.20.0/docs/#over)) and allows one to map over the | ||
focused element of a data structure. | ||
@@ -350,11 +338,11 @@ | ||
```js | ||
> L.over("elems", R.map(L.delete("x")), {elems: [{x: 1, y: 2}, {x: 3, y: 4}]}) | ||
{elems: [{y: 2}, {y: 4}]} | ||
L.over("elems", R.map(L.remove("x")), {elems: [{x: 1, y: 2}, {x: 3, y: 4}]}) | ||
// {elems: [{y: 2}, {y: 4}]} | ||
``` | ||
#### [`L.set(l, x, s)`](#lsetl-x-s "L.set :: PLens s a -> Maybe a -> Maybe s -> Maybe s") | ||
#### [`L.remove(l, s)`](#lremovel-s "L.remove :: PLens s a -> Maybe s -> Maybe s") | ||
`L.set(l, x, s)` is the same as `R.set(lift(l), x, s)` (see | ||
[set](http://ramdajs.com/0.19.0/docs/#set)) and is also equivalent to `L.over(l, | ||
() => x, s)`. | ||
`L.remove(l, s)` is equivalent to `L.set(l, undefined, s)`. With partial | ||
lenses, setting to undefined typically has the effect of removing the focused | ||
element. | ||
@@ -364,11 +352,12 @@ For example: | ||
```js | ||
> L.set(L("a", 0, "x"), 11, {id: "z"}) | ||
{a: [{x: 11}], id: "z"} | ||
L.remove(P("a", "b"), {a: {b: 1}, x: {y: 2}}) | ||
// {x: {y: 2}} | ||
``` | ||
#### [`L.view(l, s)`](#lviewl-s "L.view :: PLens s a -> Maybe s -> Maybe a") | ||
#### [`L.removeAll(l, s)`](#lremovealll-s "L.removeAll :: PLens s a -> Maybe s -> Maybe s") | ||
`L.view(l, s)` is the same as `R.view(lift(l), s)` (see | ||
[view](http://ramdajs.com/0.19.0/docs/#view)) and returns the focused element | ||
from a data structure. | ||
`L.removeAll(l, s)` removes all the non `undefined` items targeted by the lens | ||
`l` from `s`. This only makes sense for a lens that | ||
* can potentially focus on more than one item and | ||
* will focus on `undefined` when it doesn't find an item to focus on. | ||
@@ -378,42 +367,26 @@ For example: | ||
```js | ||
> L.view("y", {x: 112, y: 101}) | ||
101 | ||
L.removeAll(L.findWith("a"), [{x: 1}, {a: 2}, {a: 3, y: 4}, {z: 5}]) | ||
// [{x: 1}, {y: 4}, {z: 5}] | ||
``` | ||
#### Lifting | ||
#### [`L.set(l, x, s)`](#lsetl-x-s "L.set :: PLens s a -> Maybe a -> Maybe s -> Maybe s") | ||
The idempotent `lift` operation is defined as | ||
`L.set(l, x, s)` is the same as `R.set(lift(l), x, s)` (see | ||
[set](http://ramdajs.com/0.20.0/docs/#set)) and is also equivalent to `L.over(l, | ||
() => x, s)`. Assuming that `0 <= i && i < xs.length` and `x !== undefined` | ||
then `L.set(i, x, xs)` is also equivalent to `R.update(i, x, xs)` (see | ||
[update](http://ramdajs.com/0.20.0/docs/#update)). | ||
```js | ||
const lift = l => { | ||
switch (typeof l) { | ||
case "string": return L.prop(l) | ||
case "number": return L.index(l) | ||
default: return l | ||
} | ||
} | ||
``` | ||
and is available as a non-default export. All operations in this library that | ||
take lenses as arguments implicitly lift them. | ||
#### [`L.delete(l, s)`](#ldeletel-s "L.delete :: PLens s a -> Maybe s -> Maybe s") | ||
`L.delete(l, s)` is equivalent to `L.set(l, undefined, s)`. With partial | ||
lenses, setting to undefined typically has the effect of removing the focused | ||
element. | ||
For example: | ||
```js | ||
> L.delete(L("a", "b"), {a: {b: 1}, x: {y: 2}}) | ||
{x: {y: 2}} | ||
L.set(P("a", 0, "x"), 11, {id: "z"}) | ||
// {a: [{x: 11}], id: "z"} | ||
``` | ||
#### [`L.deleteAll(l, s)`](#ldeletealll-s "L.deleteAll :: PLens s a -> Maybe s -> Maybe s") | ||
#### [`L.view(l, s)`](#lviewl-s "L.view :: PLens s a -> Maybe s -> Maybe a") | ||
`L.deleteAll(l, s)` deletes all the non `undefined` items targeted by the lens | ||
`l` from `s`. This only makes sense for a lens that | ||
* can potentially focus on more than one item and | ||
* will focus on `undefined` when it doesn't find an item to focus on. | ||
`L.view(l, s)` is the same as `R.view(lift(l), s)` (see | ||
[view](http://ramdajs.com/0.20.0/docs/#view)) and returns the focused element | ||
from a data structure. | ||
@@ -423,7 +396,7 @@ For example: | ||
```js | ||
> L.deleteAll(L.findWith("a"), [{x: 1}, {a: 2}, {a: 3, y: 4}, {z: 5}]) | ||
[{x: 1}, {y: 4}, {z: 5}] | ||
L.view("y", {x: 112, y: 101}) | ||
// 101 | ||
``` | ||
### Lenses | ||
### Lens combinators | ||
@@ -442,4 +415,4 @@ In alphabetical order. | ||
```js | ||
> L.set(L.append, "x", undefined) | ||
[ 'x' ] | ||
L.set(L.append, "x", undefined) | ||
// [ 'x' ] | ||
``` | ||
@@ -458,4 +431,4 @@ | ||
```js | ||
> L.over(L.augment({y: r => r.x + 1}), r => ({x: r.x + r.y, y: 2, z: r.x - r.y}), {x: 1}) | ||
{ x: 3, z: -1 } | ||
L.over(L.augment({y: r => r.x + 1}), r => ({x: r.x + r.y, y: 2, z: r.x - r.y}), {x: 1}) | ||
// { x: 3, z: -1 } | ||
``` | ||
@@ -481,10 +454,46 @@ | ||
```js | ||
> L.view(majorAxis, {x: 1, y: 2}) | ||
2 | ||
> L.view(majorAxis, {x: -3, y: 1}) | ||
-3 | ||
> L.over(majorAxis, R.negate, {x: 2, y: -3}) | ||
{ y: 3, x: 2 } | ||
L.view(majorAxis, {x: 1, y: 2}) | ||
// 2 | ||
L.view(majorAxis, {x: -3, y: 1}) | ||
// -3 | ||
L.over(majorAxis, R.negate, {x: 2, y: -3}) | ||
// { y: 3, x: 2 } | ||
``` | ||
#### [`L.compose(l, ...ls)`](#lcomposel-ls "L.compose :: (PLens s s1, ...PLens sN a) -> PLens s a") | ||
The default import `P(l, ...ls)` and `L.compose(l, ...ls)` both are the same as | ||
`R.compose(lift(l), ...ls.map(lift))` (see | ||
[compose](http://ramdajs.com/0.20.0/docs/#compose)) and compose a lens from a | ||
path of lenses. Furthermore, `L.compose()` is the same as `L.identity`, which | ||
reflects the fact that `L.identity` is the identity element of lens composition. | ||
For example: | ||
```js | ||
L.view(P("a", 1), {a: ["b", "c"]}) | ||
// "c" | ||
``` | ||
#### [`L.defaults(out)`](#ldefaultsout "L.defaults :: s -> PLens s s") | ||
`L.defaults(out)` is the same as `L.replace(undefined, out)`. `L.defaults` is | ||
used to specify a default value for an element in case it is missing. This can | ||
be useful to avoid having to check for and provide default behavior elsewhere. | ||
For example: | ||
```js | ||
L.view(P("items", L.defaults([])), {}) | ||
// [] | ||
L.view(P("items", L.defaults([])), {items: [1, 2, 3]}) | ||
// [ 1, 2, 3 ] | ||
``` | ||
#### [`L.define(value)`](#ldefinevalue "L.define :: s -> PLens s s") | ||
`L.define(value)` is the same as `P(L.required(value), L.defaults(value))`. | ||
`L.define` is used to specify a value to act as both the default value and the | ||
required value for an element. | ||
#### [`L.filter(predicate)`](#lfilterpredicate "L.filter :: (a -> Boolean) -> PLens [a] [a]") | ||
@@ -501,4 +510,4 @@ | ||
```js | ||
> L.delete(L.filter(x => x <= 2), [3,1,4,1,5,9,2]) | ||
[ 3, 4, 5, 9 ] | ||
L.remove(L.filter(x => x <= 2), [3,1,4,1,5,9,2]) | ||
// [ 3, 4, 5, 9 ] | ||
``` | ||
@@ -521,4 +530,4 @@ | ||
```js | ||
> L.deleteAll(L.find(x => x <= 2), [3,1,4,1,5,9,2]) | ||
[ 3, 4, 5, 9 ] | ||
L.removeAll(L.find(x => x <= 2), [3,1,4,1,5,9,2]) | ||
// [ 3, 4, 5, 9 ] | ||
``` | ||
@@ -529,3 +538,3 @@ | ||
`L.findWith(l, ...ls)` chooses an index from an array through which the given | ||
lens, `L(l, ...ls)`, focuses on a defined item and then returns a lens that | ||
lens, `P(l, ...ls)`, focuses on a defined item and then returns a lens that | ||
focuses on that item. | ||
@@ -536,6 +545,6 @@ | ||
```js | ||
> L.view(L.findWith("x"), [{z: 6}, {x: 9}, {y: 6}]) | ||
9 | ||
> L.set(L.findWith("x"), 3, [{z: 6}, {x: 9}, {y: 6}]) | ||
[ { z: 6 }, { x: 3 }, { y: 6 } ] | ||
L.view(L.findWith("x"), [{z: 6}, {x: 9}, {y: 6}]) | ||
// 9 | ||
L.set(L.findWith("x"), 3, [{z: 6}, {x: 9}, {y: 6}]) | ||
// [ { z: 6 }, { x: 3 }, { y: 6 } ] | ||
``` | ||
@@ -556,3 +565,3 @@ | ||
`L.identity` is equivalent to `R.lens(R.identity, R.identity)` and is the | ||
identity element of lenses: both `L(L.identity, l)` and `L(l, L.identity)` are | ||
identity element of lenses: both `P(L.identity, l)` and `P(l, L.identity)` are | ||
equivalent to `l`. | ||
@@ -562,4 +571,4 @@ | ||
`L.index(integer)` or `L(integer)` is similar to `R.lensIndex(integer)` (see | ||
[lensIndex](http://ramdajs.com/0.19.0/docs/#lensIndex)), but acts as a partial | ||
`L.index(integer)` or `P(integer)` is similar to `R.lensIndex(integer)` (see | ||
[lensIndex](http://ramdajs.com/0.20.0/docs/#lensIndex)), but acts as a partial | ||
lens: | ||
@@ -573,2 +582,35 @@ * When viewing an undefined array index or an undefined array, the result is | ||
**NOTE:** There is a gotcha related to removing elements from an array. Namely, | ||
when the last element is removed, the result is `undefined` rather than an empty | ||
array. This is by design, because this allows the removal to propagate upwards. | ||
It is not uncommon, however, to have cases where removing the last element from | ||
an array must not remove the array itself. In such cases you want to use | ||
`L.required([])` to access the array. Consider the following examples without | ||
`L.required([])`: | ||
```js | ||
L.remove(0, ["a", "b"]) | ||
// [ 'b' ] | ||
L.remove(0, ["b"]) | ||
// undefined | ||
L.remove(P("elems", 0), {elems: ["b"], some: "thing"}) | ||
// { some: 'thing' } | ||
``` | ||
Then consider the same examples with `L.required([])`: | ||
```js | ||
L.remove(P(L.required([]), 0), ["a", "b"]) | ||
// [ 'b' ] | ||
L.remove(P(L.required([]), 0), ["b"]) | ||
// [] | ||
L.remove(P("elems", L.required([]), 0), {elems: ["b"], some: "thing"}) | ||
// { elems: [], some: 'thing' } | ||
``` | ||
#### [`L.lens(get, set)`](#llensget-set "L.lens :: (Maybe s -> Maybe a) -> (Maybe a -> Maybe s -> Maybe s) -> PLens s a") | ||
`L.lens(get, set)` is the same as `R.lens(get, set)` (see | ||
[lens](http://ramdajs.com/0.20.0/docs/#lens)) and creates a new primitive lens. | ||
#### [`L.normalize(value => value)`](#lnormalizevalue--value "L.normalize :: (s -> s) -> PLens s s") | ||
@@ -617,4 +659,4 @@ | ||
```js | ||
> L.view(sanitize, data) | ||
{ pos: { x: 1, y: 2 }, vel: { x: 1, y: 0 } } | ||
L.view(sanitize, data) | ||
// { pos: { x: 1, y: 2 }, vel: { x: 1, y: 0 } } | ||
``` | ||
@@ -625,4 +667,4 @@ | ||
```js | ||
> L.over(L(sanitize, "pos", "x"), R.add(5), data) | ||
{ px: 6, py: 2, vx: 1, vy: 0 } | ||
L.over(P(sanitize, "pos", "x"), R.add(5), data) | ||
// { px: 6, py: 2, vx: 1, vy: 0 } | ||
``` | ||
@@ -637,9 +679,9 @@ | ||
Note that, when set, `L.pick` simply ignores any properties that the given | ||
template doesn't mention. Note that the underlying data structure need not be | ||
an object. | ||
template doesn't mention. Also note that the underlying data structure need not | ||
be an object. | ||
#### [`L.prop(string)`](#lpropstring "L.prop :: (p :: a) -> PLens {p :: a, ...ps} a") | ||
`L.prop(string)` or `L(string)` is similar to `R.lensProp(string)` (see | ||
[lensProp](http://ramdajs.com/0.19.0/docs/#lensProp)), but acts as a partial | ||
`L.prop(string)` or `P(string)` is similar to `R.lensProp(string)` (see | ||
[lensProp](http://ramdajs.com/0.20.0/docs/#lensProp)), but acts as a partial | ||
lens: | ||
@@ -662,4 +704,4 @@ * When viewing an undefined property or an undefined object, the result is | ||
```js | ||
> L.set(L.props("x", "y"), {x: 4}, {x: 1, y: 2, z: 3}) | ||
{ z: 3, x: 4 } | ||
L.set(L.props("x", "y"), {x: 4}, {x: 1, y: 2, z: 3}) | ||
// { z: 3, x: 4 } | ||
``` | ||
@@ -671,3 +713,3 @@ | ||
versa when set. Values are compared using `R.equals` (see | ||
[equals](http://ramdajs.com/0.19.0/docs/#equals)). | ||
[equals](http://ramdajs.com/0.20.0/docs/#equals)). | ||
@@ -677,6 +719,6 @@ For example: | ||
```js | ||
> L.view(L.replace(1, 2), 1) | ||
2 | ||
> L.set(L.replace(1, 2), 2, 0) | ||
1 | ||
L.view(L.replace(1, 2), 1) | ||
// 2 | ||
L.set(L.replace(1, 2), 2, 0) | ||
// 1 | ||
``` | ||
@@ -686,9 +728,9 @@ | ||
and elements. In most cases, rather than using `replace`, you will make | ||
selective use of `default` and `required`: | ||
selective use of `defaults` and `required`. | ||
##### [`L.default(out)`](#ldefaultout "L.default :: s -> PLens s s") | ||
#### [`L.required(inn)`](#lrequiredinn "L.required :: s -> PLens s s") | ||
`L.default(out)` is the same as `L.replace(undefined, out)`. `L.default` is | ||
used to specify a default value for an element in case it is missing. This can | ||
be useful to avoid having to check for and provide default behavior elsewhere. | ||
`L.required(inn)` is the same as `L.replace(inn, undefined)`. `L.required` is | ||
used to specify that an element is not to be removed; in case it is removed, the | ||
given value will be substituted instead. | ||
@@ -698,31 +740,29 @@ For example: | ||
```js | ||
> L.view(L("items", L.default([])), {}) | ||
[] | ||
> L.view(L("items", L.default([])), {items: [1, 2, 3]}) | ||
[ 1, 2, 3 ] | ||
L.remove(P("items", 0), {items: [1]}) | ||
// undefined | ||
L.remove(P(L.required({}), "items", 0), {items: [1]}) | ||
// {} | ||
L.remove(P("items", L.required([]), 0), {items: [1]}) | ||
// { items: [] } | ||
``` | ||
##### [`L.define(value)`](#ldefinevalue "L.define :: s -> PLens s s") | ||
### Auxiliary | ||
`L.define(value)` is the same as `L(L.required(value), L.default(value))`. | ||
`L.define` is used to specify a value to act as both the default value and the | ||
required value for an element. | ||
#### [`L.lift(pl)`](#lliftpl "L.lift :: (p :: a) -> PLens {p :: a, ...ps} a & Integer -> PLens [a] a & PLens s a -> PLens s a") | ||
##### [`L.required(inn)`](#lrequiredinn "L.required :: s -> PLens s s") | ||
The idempotent `lift` operation is defined as | ||
`L.required(inn)` is the same as `L.replace(inn, undefined)`. `L.required` is | ||
used to specify that an element is not to be deleted; in case it is deleted, the | ||
given value will be substituted instead. | ||
For example: | ||
```js | ||
> L.delete(L("items", 0), {items: [1]}) | ||
undefined | ||
> L.delete(L(L.required({}), "items", 0), {items: [1]}) | ||
{} | ||
> L.delete(L("items", L.required([]), 0), {items: [1]}) | ||
{ items: [] } | ||
const lift = l => { | ||
switch (typeof l) { | ||
case "string": return L.prop(l) | ||
case "number": return L.index(l) | ||
default: return l | ||
} | ||
} | ||
``` | ||
and is available as a non-default export. All operations in this library that | ||
take lenses as arguments implicitly lift them. | ||
## Background | ||
@@ -735,14 +775,14 @@ | ||
```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 } } | ||
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 } } | ||
``` | ||
@@ -755,3 +795,3 @@ | ||
`R.compose(L.prop(p0), ...ps.map(L.prop))` or just use the shorthand notation | ||
`L(p0, ...ps)`. | ||
`P(p0, ...ps)`. | ||
@@ -783,2 +823,2 @@ ### Types | ||
ordinary lenses (e.g. Ramda's | ||
[lensProp](http://ramdajs.com/0.19.0/docs/#lensProp)). | ||
[lensProp](http://ramdajs.com/0.20.0/docs/#lensProp)). |
@@ -43,5 +43,5 @@ import R from "ramda" | ||
const conserve = (c0, c1) => R.equals(c0, c1) ? c0 : c1 | ||
const conserve = (c1, c0) => R.equals(c1, c0) ? c0 : c1 | ||
const toConserve = f => (y, c0) => conserve(c0, f(y, c0)) | ||
const toConserve = f => (y, c0) => conserve(f(y, c0), c0) | ||
@@ -52,4 +52,4 @@ // | ||
switch (typeof l) { | ||
case "string": return L.prop(l) | ||
case "number": return L.index(l) | ||
case "string": return prop(l) | ||
case "number": return index(l) | ||
default: return l | ||
@@ -59,18 +59,21 @@ } | ||
const L = (l, ...ls) => | ||
ls.length === 0 ? lift(l) : R.compose(lift(l), ...ls.map(lift)) | ||
export const compose = (...ls) => | ||
ls.length === 0 ? identity : | ||
ls.length === 1 ? lift(ls[0]) : | ||
R.compose(...ls.map(lift)) | ||
L.compose = L | ||
L.delete = R.curry((l, s) => R.set(lift(l), undefined, s)) | ||
L.deleteAll = R.curry((lens, data) => { | ||
while (L.view(lens, data) !== undefined) | ||
data = L.delete(lens, data) | ||
export const remove = R.curry((l, s) => R.set(lift(l), undefined, s)) | ||
export const removeAll = R.curry((lens, data) => { | ||
while (view(lens, data) !== undefined) | ||
data = remove(lens, data) | ||
return data | ||
}) | ||
L.lens = R.lens | ||
L.over = R.curry((l, x2x, s) => R.over(lift(l), x2x, s)) | ||
L.set = R.curry((l, x, s) => R.set(lift(l), x, s)) | ||
L.view = R.curry((l, s) => R.view(lift(l), s)) | ||
L.choose = x2yL => toFunctor => target => { | ||
export const lens = R.lens | ||
export const over = R.curry((l, x2x, s) => R.over(lift(l), x2x, s)) | ||
export const set = R.curry((l, x, s) => R.set(lift(l), x, s)) | ||
export const view = R.curry((l, s) => R.view(lift(l), s)) | ||
export const choose = x2yL => toFunctor => target => { | ||
const l = lift(x2yL(target)) | ||
@@ -80,35 +83,35 @@ return R.map(focus => R.set(l, focus, target), toFunctor(R.view(l, target))) | ||
L.firstOf = (l, ...ls) => L.choose(x => { | ||
export const firstOf = (l, ...ls) => choose(x => { | ||
const lls = [l, ...ls] | ||
return lls[Math.max(0, lls.findIndex(l => L.view(l, x) !== undefined))] | ||
return lls[Math.max(0, lls.findIndex(l => view(l, x) !== undefined))] | ||
}) | ||
L.replace = R.curry((inn, out) => | ||
export const replace = R.curry((inn, out) => | ||
R.lens(x => R.equals(x, inn) ? out : x, | ||
toConserve(y => R.equals(y, out) ? inn : y))) | ||
L.default = L.replace(undefined) | ||
L.required = inn => L.replace(inn, undefined) | ||
L.define = v => R.compose(L.required(v), L.default(v)) | ||
export const defaults = replace(undefined) | ||
export const required = inn => replace(inn, undefined) | ||
export const define = v => R.compose(required(v), defaults(v)) | ||
L.normalize = transform => | ||
export const normalize = transform => | ||
R.lens(toPartial(transform), toConserve(toPartial(transform))) | ||
L.prop = k => | ||
export const prop = k => | ||
R.lens(o => o && o[k], | ||
(v, o) => v === undefined ? deleteKey(k, o) : setKey(k, v, o)) | ||
L.find = predicate => L.choose(xs => { | ||
export const find = predicate => choose(xs => { | ||
if (xs === undefined) | ||
return L.append | ||
return append | ||
const i = xs.findIndex(predicate) | ||
return i < 0 ? L.append : i | ||
return i < 0 ? append : i | ||
}) | ||
L.findWith = (l, ...ls) => { | ||
const lls = L(l, ...ls) | ||
return L(L.find(x => R.view(lls, x) !== undefined), lls) | ||
export const findWith = (l, ...ls) => { | ||
const lls = compose(l, ...ls) | ||
return compose(find(x => R.view(lls, x) !== undefined), lls) | ||
} | ||
L.index = i => R.lens(xs => xs && xs[i], (x, xs) => { | ||
export const index = i => R.lens(xs => xs && xs[i], (x, xs) => { | ||
if (x === undefined) { | ||
@@ -131,9 +134,9 @@ if (xs === undefined) | ||
L.append = R.lens(() => {}, (x, xs) => | ||
export const append = R.lens(() => {}, (x, xs) => | ||
x === undefined ? xs : xs === undefined ? [x] : xs.concat([x])) | ||
L.filter = p => R.lens(xs => xs && xs.filter(p), (ys, xs) => | ||
conserve(xs, dropped(R.concat(ys || [], (xs || []).filter(R.complement(p)))))) | ||
export const filter = p => R.lens(xs => xs && xs.filter(p), (ys, xs) => | ||
conserve(dropped(R.concat(ys || [], (xs || []).filter(R.complement(p)))), xs)) | ||
L.augment = template => R.lens( | ||
export const augment = template => R.lens( | ||
toPartial(x => { | ||
@@ -164,7 +167,7 @@ const z = {...x} | ||
L.pick = template => R.lens( | ||
export const pick = template => R.lens( | ||
c => { | ||
let r | ||
for (const k in template) { | ||
const v = L.view(template[k], c) | ||
const v = view(template[k], c) | ||
if (v !== undefined) { | ||
@@ -181,13 +184,13 @@ if (r === undefined) | ||
for (const k in template) | ||
c = L.set(template[k], o[k], c) | ||
c = set(template[k], o[k], c) | ||
return c | ||
}) | ||
L.identity = R.lens(R.identity, R.identity) | ||
export const identity = R.lens(R.identity, conserve) | ||
L.props = (k, ...ks) => { | ||
export const props = (k, ...ks) => { | ||
const kks = [k, ...ks] | ||
return L.pick(R.zipObj(kks, kks)) | ||
return pick(R.zipObj(kks, kks)) | ||
} | ||
export default L | ||
export default compose |
import R from "ramda" | ||
import L from "../src/partial.lenses" | ||
import P, * as L from "../src/partial.lenses" | ||
@@ -16,3 +16,3 @@ function show(x) { | ||
const testEq = (expr, expect) => it(`${expr} => ${show(expect)}`, () => { | ||
const actual = eval(`(L, R) => ${expr}`)(L, R) | ||
const actual = eval(`(P, L, R) => ${expr}`)(P, L, R) | ||
if (!R.equals(actual, expect)) | ||
@@ -22,8 +22,14 @@ throw new Error(`Expected: ${show(expect)}, actual: ${show(actual)}`) | ||
describe("default === compose", () => { | ||
it("P === L.compose", () => { | ||
if (P !== L.compose) | ||
throw new Error("Not the same") | ||
}) | ||
}) | ||
describe("arities", () => { | ||
testEq('L.augment.length', 1) | ||
testEq('L.compose.length', 1) | ||
testEq('L.default.length', 1) | ||
testEq('L.compose.length', 0) | ||
testEq('L.defaults.length', 1) | ||
testEq('L.define.length', 1) | ||
testEq('L.delete.length', 2) | ||
testEq('L.filter.length', 1) | ||
@@ -33,3 +39,2 @@ testEq('L.find.length', 1) | ||
testEq('L.index.length', 1) | ||
testEq('L.length', 1) | ||
testEq('L.lens.length', 2) | ||
@@ -41,2 +46,3 @@ testEq('L.normalize.length', 1) | ||
testEq('L.props.length', 1) | ||
testEq('L.remove.length', 2) | ||
testEq('L.replace.length', 2) | ||
@@ -60,13 +66,13 @@ testEq('L.required.length', 1) | ||
describe('L.index', () => { | ||
testEq('L.set(L(1), undefined, [,,])', undefined) | ||
testEq('L.set(L.compose(L.required([]), 1), undefined, [,,])', []) | ||
testEq('L.set(L(1), 4, [1, 2, 3])', [1, 4, 3]) | ||
testEq('L.set(P(1), undefined, [,,])', undefined) | ||
testEq('L.set(P(L.required([]), 1), undefined, [,,])', []) | ||
testEq('L.set(P(1), 4, [1, 2, 3])', [1, 4, 3]) | ||
testEq('L.set(2, 4, undefined)', [,, 4]) | ||
testEq('L.set(L(2), 4, [1])', [1,, 4]) | ||
testEq('L.delete(L(0), [1, 2, 3])', [2, 3]) | ||
testEq('L.set(L(1), undefined, [1, 2, 3])', [1, 3]) | ||
testEq('L.set(P(2), 4, [1])', [1,, 4]) | ||
testEq('L.remove(P(0), [1, 2, 3])', [2, 3]) | ||
testEq('L.set(P(1), undefined, [1, 2, 3])', [1, 3]) | ||
testEq('L.set(2, undefined, [1, 2, 3])', [1, 2]) | ||
testEq('L.set(L(5), undefined, [1, 2, 3])', [1, 2, 3]) | ||
testEq('L.set(P(5), undefined, [1, 2, 3])', [1, 2, 3]) | ||
testEq('L.view(5, undefined)', undefined) | ||
testEq('L.view(L(5), [1, 2, 3])', undefined) | ||
testEq('L.view(P(5), [1, 2, 3])', undefined) | ||
testEq('L.set(1, "2", ["1", "2", "3"])', ["1", "2", "3"]) | ||
@@ -76,11 +82,11 @@ }) | ||
describe('L.prop', () => { | ||
testEq('L.set(L("x"), undefined, {x: 1})', undefined) | ||
testEq('L.set(L("x", L.required(null)), undefined, {x: 1})', {x: null}) | ||
testEq('L.set(L.compose("x", L.required(null)), 2, {x: 1})', {x: 2}) | ||
testEq('L.delete("y", {x: 1, y: 2})', {x: 1}) | ||
testEq('L.set(L("y"), 3, {x: 1, y: 2})', {x: 1, y: 3}) | ||
testEq('L.set(P("x"), undefined, {x: 1})', undefined) | ||
testEq('L.set(P("x", L.required(null)), undefined, {x: 1})', {x: null}) | ||
testEq('L.set(P("x", L.required(null)), 2, {x: 1})', {x: 2}) | ||
testEq('L.remove("y", {x: 1, y: 2})', {x: 1}) | ||
testEq('L.set(P("y"), 3, {x: 1, y: 2})', {x: 1, y: 3}) | ||
testEq('L.set("z", 3, {x: 1, y: 2})', {x: 1, y: 2, z: 3}) | ||
testEq('L.set(L("z"), 3, undefined)', {z: 3}) | ||
testEq('L.set(P("z"), 3, undefined)', {z: 3}) | ||
testEq('L.view("z", undefined)', undefined) | ||
testEq('L.view(L("z"), {x: 1})', undefined) | ||
testEq('L.view(P("z"), {x: 1})', undefined) | ||
}) | ||
@@ -95,7 +101,7 @@ | ||
describe("L.default", () => { | ||
testEq('L.view(L.default(""), undefined)', "") | ||
testEq('L.view(L.default(""), "defined")', "defined") | ||
testEq('L.set(L.default(""), "", "anything")', undefined) | ||
testEq('L.set(L.default(""), "defined", "anything")', "defined") | ||
describe("L.defaults", () => { | ||
testEq('L.view(L.defaults(""), undefined)', "") | ||
testEq('L.view(L.defaults(""), "defined")', "defined") | ||
testEq('L.set(L.defaults(""), "", "anything")', undefined) | ||
testEq('L.set(L.defaults(""), "defined", "anything")', "defined") | ||
}) | ||
@@ -105,9 +111,9 @@ | ||
testEq('L.view(L.normalize(R.sortBy(R.identity)), [1,3,2,5])', [1,2,3,5]) | ||
testEq('L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), 4, [1,3,2,5])', | ||
testEq('L.set(P(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), 4, [1,3,2,5])', | ||
[1,3,4,5]) | ||
testEq('L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), 4, undefined)', | ||
testEq('L.set(P(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), 4, undefined)', | ||
[4]) | ||
testEq('L.delete(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), [2])', | ||
testEq('L.remove(P(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), [2])', | ||
undefined) | ||
testEq('L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), undefined, [1,3,2,5])', | ||
testEq('L.set(P(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), undefined, [1,3,2,5])', | ||
[1,3,5]) | ||
@@ -124,5 +130,5 @@ }) | ||
testEq('L.set(L.firstOf("y", "x"), 12, {z: 13})', {y: 12, z: 13}) | ||
testEq('L.delete(L.firstOf("x", "y"), {z: 13})', {z: 13}) | ||
testEq('L.delete(L.firstOf("x", "y"), {x: 11, y: 12})', {y: 12}) | ||
testEq('L.delete(L.firstOf("y", "x"), {x: 11, y: 12})', {x: 11}) | ||
testEq('L.remove(L.firstOf("x", "y"), {z: 13})', {z: 13}) | ||
testEq('L.remove(L.firstOf("x", "y"), {x: 11, y: 12})', {y: 12}) | ||
testEq('L.remove(L.firstOf("y", "x"), {x: 11, y: 12})', {x: 11}) | ||
}) | ||
@@ -133,3 +139,3 @@ | ||
testEq('L.set(L.findWith("x", 1), "d", [{x: ["a"]},{x: ["b","c"]}])', [{x: ["a"]},{x: ["b","d"]}]) | ||
testEq('L.delete(L.findWith("x", 1), [{x: ["a"]},{x: ["b","c"]}])', [{x: ["a"]},{x: ["b"]}]) | ||
testEq('L.remove(L.findWith("x", 1), [{x: ["a"]},{x: ["b","c"]}])', [{x: ["a"]},{x: ["b"]}]) | ||
}) | ||
@@ -141,10 +147,10 @@ | ||
testEq('L.view(L.filter(R.lt(2)), [3,1,4,1,5,9,2])', [3,4,5,9]) | ||
testEq('L.delete(L(L.filter(R.lt(2)), 1), [3,1,4,1,5,9,2])', [3,5,9,1,1,2]) | ||
testEq('L.remove(P(L.filter(R.lt(2)), 1), [3,1,4,1,5,9,2])', [3,5,9,1,1,2]) | ||
testEq('L.set(L.filter(R.lt(0)), [], [3,1,4,1,5,9,2])', undefined) | ||
testEq('L.delete(L.filter(R.lt(0)), [3,1,4,1,5,9,2])', undefined) | ||
testEq('L.delete(L.filter(R.lt(2)), [3,1,4,1,5,9,2])', [1,1,2]) | ||
testEq('L.remove(L.filter(R.lt(0)), [3,1,4,1,5,9,2])', undefined) | ||
testEq('L.remove(L.filter(R.lt(2)), [3,1,4,1,5,9,2])', [1,1,2]) | ||
}) | ||
describe("L.deleteAll", () => { | ||
testEq('L.deleteAll(L.find(x => x < 2), [3,1,4,1,5,9,2])', [3,4,5,9,2]) | ||
describe("L.removeAll", () => { | ||
testEq('L.removeAll(L.find(x => x < 2), [3,1,4,1,5,9,2])', [3,4,5,9,2]) | ||
}) | ||
@@ -157,4 +163,4 @@ | ||
testEq('L.set(L.augment({y: c => c.x+1}), {x: 2, y: 1}, {x: 0, y: -1})', {x: 2, y: -1}) | ||
testEq('L.delete(L(L.augment({y: () => 1}), "x"), {x:0})', undefined) | ||
testEq('L.delete(L.augment({z: c => c.x + c.y}), {x: 1, y: 2})', undefined) | ||
testEq('L.remove(P(L.augment({y: () => 1}), "x"), {x:0})', undefined) | ||
testEq('L.remove(L.augment({z: c => c.x + c.y}), {x: 1, y: 2})', undefined) | ||
}) | ||
@@ -164,8 +170,8 @@ | ||
testEq('L.view(L.pick({x: "c"}), {a: [2], b: 1})', undefined) | ||
testEq('L.set(L(L.pick({x: "c"}), "x"), 4, {a: [2], b: 1})', {a: [2], b: 1, c: 4}) | ||
testEq('L.set(P(L.pick({x: "c"}), "x"), 4, {a: [2], b: 1})', {a: [2], b: 1, c: 4}) | ||
testEq('L.view(L.pick({x: "b", y: "a"}), {a: [2], b: 1})', {x: 1, y: [2]}) | ||
testEq('L.set(L(L.pick({x: "b", y: "a"}), "x"), 3, {a: [2], b: 1})', {a: [2], b: 3}) | ||
testEq('L.delete(L(L.pick({x: "b", y: "a"}), "y"), {a: [2], b: 1})', {b: 1}) | ||
testEq('L.delete(L(L.pick({x: "b"}), "x"), {a: [2], b: 1})', {a: [2]}) | ||
testEq('L.deleteAll(L(L.pick({x: "b", y: "a"}), L.firstOf("y", "x")), {a: [2], b: 1})', undefined) | ||
testEq('L.set(P(L.pick({x: "b", y: "a"}), "x"), 3, {a: [2], b: 1})', {a: [2], b: 3}) | ||
testEq('L.remove(P(L.pick({x: "b", y: "a"}), "y"), {a: [2], b: 1})', {b: 1}) | ||
testEq('L.remove(P(L.pick({x: "b"}), "x"), {a: [2], b: 1})', {a: [2]}) | ||
testEq('L.removeAll(P(L.pick({x: "b", y: "a"}), L.firstOf("y", "x")), {a: [2], b: 1})', undefined) | ||
}) | ||
@@ -177,6 +183,6 @@ | ||
testEq('L.view(L.props("x", "y"), {x: 2, z: 3})', {x: 2}) | ||
testEq('L.delete(L.props("x", "y"), {x: 1, y: 2, z: 3})', {z: 3}) | ||
testEq('L.remove(L.props("x", "y"), {x: 1, y: 2, z: 3})', {z: 3}) | ||
testEq('L.set(L.props("x", "y"), {}, {x: 1, y: 2, z: 3})', {z: 3}) | ||
testEq('L.set(L.props("x", "y"), {y: 4}, {x: 1, y: 2, z: 3})', {y: 4, z: 3}) | ||
testEq('L.delete(L.props("x", "y"), {x: 1, y: 2})', undefined) | ||
testEq('L.remove(L.props("x", "y"), {x: 1, y: 2})', undefined) | ||
testEq('L.set(L.props("a", "b"), {a: 2}, {a: 1, b: 3})', {a: 2}) | ||
@@ -188,3 +194,3 @@ }) | ||
const rec = | ||
L(L.normalize(n => | ||
P(L.normalize(n => | ||
undefined !== n.value ? n : | ||
@@ -194,5 +200,5 @@ n.smaller && !n.greater ? n.smaller : | ||
L.set(BST.search(n.smaller.key), n.smaller, n.greater)), | ||
L.default({key}), | ||
L.choose(n => key < n.key ? L("smaller", rec) : | ||
n.key < key ? L("greater", rec) : | ||
L.defaults({key}), | ||
L.choose(n => key < n.key ? P("smaller", rec) : | ||
n.key < key ? P("greater", rec) : | ||
L.identity)) | ||
@@ -202,3 +208,3 @@ return rec | ||
valueOf: key => L(BST.search(key), "value"), | ||
valueOf: key => P(BST.search(key), "value"), | ||
@@ -243,3 +249,3 @@ isValid: (n, keyPred = () => true) => | ||
case "delete": | ||
after = L.delete(BST.valueOf(key), before) | ||
after = L.remove(BST.valueOf(key), before) | ||
if (undefined !== L.view(BST.valueOf(key), after)) | ||
@@ -246,0 +252,0 @@ error() |
Sorry, the diff of this file is not supported yet
175272
23
1010
781
+ Addedramda@0.20.1(transitive)
- Removedramda@0.19.1(transitive)
Updatedramda@^0.20.0