partial.lenses
Advanced tools
Comparing version 0.5.1 to 0.6.0
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,2 +8,4 @@ value: true | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _ramda = require("ramda"); | ||
@@ -60,6 +60,9 @@ | ||
var conserve = function conserve(f) { | ||
return function (n0, o) { | ||
var n = f(n0, o); | ||
return _ramda2.default.equals(n, o) ? o : n; | ||
var conserve = function conserve(c0, c1) { | ||
return _ramda2.default.equals(c0, c1) ? c0 : c1; | ||
}; | ||
var toConserve = function toConserve(f) { | ||
return function (y, c0) { | ||
return conserve(c0, f(y, c0)); | ||
}; | ||
@@ -104,26 +107,9 @@ }; | ||
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]; | ||
} | ||
l0 = lift(l0); | ||
if (ls.length === 0) return l0; | ||
L.choose = function (x2yL) { | ||
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; | ||
var l = lift(x2yL(target)); | ||
return _ramda2.default.map(function (focus) { | ||
return _ramda2.default.set(l, focus, target); | ||
}, toFunctor(r)); | ||
}, toFunctor(_ramda2.default.view(l, target))); | ||
}; | ||
@@ -133,6 +119,19 @@ }; | ||
L.firstOf = function (l) { | ||
for (var _len2 = arguments.length, ls = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
ls[_key2 - 1] = arguments[_key2]; | ||
} | ||
return L.choose(function (x) { | ||
var lls = [l].concat(ls); | ||
return lls[Math.max(0, lls.findIndex(function (l) { | ||
return L.view(l, x) !== undefined; | ||
}))]; | ||
}); | ||
}; | ||
L.replace = _ramda2.default.curry(function (inn, out) { | ||
return _ramda2.default.lens(function (x) { | ||
return _ramda2.default.equals(x, inn) ? out : x; | ||
}, conserve(function (y) { | ||
}, toConserve(function (y) { | ||
return _ramda2.default.equals(y, out) ? inn : y; | ||
@@ -151,3 +150,3 @@ })); | ||
L.normalize = function (transform) { | ||
return _ramda2.default.lens(toPartial(transform), conserve(toPartial(transform))); | ||
return _ramda2.default.lens(toPartial(transform), toConserve(toPartial(transform))); | ||
}; | ||
@@ -164,17 +163,7 @@ | ||
L.find = function (predicate) { | ||
return _ramda2.default.lens(function (xs) { | ||
return xs && xs.find(predicate); | ||
}, function (x, xs) { | ||
if (x === undefined) { | ||
if (xs === undefined) return undefined; | ||
var i = xs.findIndex(predicate); | ||
if (i < 0) return xs; | ||
return dropped(xs.slice(0, i).concat(xs.slice(i + 1))); | ||
} else { | ||
if (xs === undefined) return [x]; | ||
var i = xs.findIndex(predicate); | ||
if (i < 0) return xs.concat([x]); | ||
if (_ramda2.default.equals(x, xs[i])) return xs; | ||
return xs.slice(0, i).concat([x], xs.slice(i + 1)); | ||
} | ||
return L.choose(function (xs) { | ||
if (xs === undefined) return L.append; | ||
var i = xs.findIndex(predicate); | ||
if (i < 0) return L.append; | ||
return L.index(i); | ||
}); | ||
@@ -200,3 +189,19 @@ }; | ||
L.append = _ramda2.default.lens(function () {}, function (x, xs) { | ||
if (x === undefined) { | ||
return xs; | ||
} else { | ||
if (xs === undefined) return [x];else return xs.concat([x]); | ||
} | ||
}); | ||
L.filter = function (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))))); | ||
}); | ||
}; | ||
exports.default = L; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9wYXJ0aWFsLmxlbnNlcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFJQSxJQUFNLFlBQVksU0FBWixTQUFZLENBQUMsQ0FBRCxFQUFJLENBQUosRUFBVTtBQUMxQixNQUFJLE1BQU0sU0FBTixJQUFtQixFQUFFLEtBQUssQ0FBTCxDQUFGLEVBQ3JCLE9BQU8sQ0FBUCxDQURGO0FBRUEsTUFBSSxhQUFKLENBSDBCO0FBSTFCLE9BQUssSUFBTSxDQUFOLElBQVcsQ0FBaEIsRUFBbUI7QUFDakIsUUFBSSxNQUFNLENBQU4sRUFBUztBQUNYLFVBQUksY0FBYyxDQUFkLEVBQ0YsSUFBSSxFQUFKLENBREY7QUFFQSxRQUFFLENBQUYsSUFBTyxFQUFFLENBQUYsQ0FBUCxDQUhXO0tBQWI7R0FERjtBQU9BLFNBQU8sQ0FBUCxDQVgwQjtDQUFWOztBQWNsQixJQUFNLFNBQVMsU0FBVCxNQUFTLENBQUMsQ0FBRCxFQUFJLENBQUosRUFBTyxDQUFQLEVBQWE7QUFDMUIsTUFBSSxNQUFNLFNBQU4sRUFDRiwyQkFBUyxHQUFJLEVBQWIsQ0FERjtBQUVBLE1BQUksS0FBSyxDQUFMLElBQVUsZ0JBQUUsTUFBRixDQUFTLENBQVQsRUFBWSxFQUFFLENBQUYsQ0FBWixDQUFWLEVBQ0YsT0FBTyxDQUFQLENBREY7QUFFQSxNQUFNLHdCQUFNLEdBQUksRUFBVixDQUxvQjtBQU0xQixPQUFLLElBQU0sQ0FBTixJQUFXLENBQWhCO0FBQ0UsUUFBSSxNQUFNLENBQU4sRUFDRixFQUFFLENBQUYsS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AgIGlmICh4cyA9PT0gdW5kZWZpbmVkKVxuICAgICAgcmV0dXJuIFt4XVxuICAgIGVsc2VcbiAgICAgIHJldHVybiB4cy5jb25jYXQoW3hdKVxuICB9XG59KVxuXG5MLmZpbHRlciA9IHAgPT4gUi5sZW5zKHhzID0+IHhzICYmIHhzLmZpbHRlcihwKSwgKHlzLCB4cykgPT5cbiAgY29uc2VydmUoeHMsIGRyb3BwZWQoUi5jb25jYXQoeXMgfHwgW10sICh4cyB8fCBbXSkuZmlsdGVyKFIuY29tcGxlbWVudChwKSkpKSkpXG5cbmV4cG9ydCBkZWZhdWx0IExcbiJdfQ== |
{ | ||
"name": "partial.lenses", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Ramda compatible lenses", | ||
@@ -14,3 +14,3 @@ "main": "lib/partial.lenses.js", | ||
"type": "git", | ||
"url": "git+https://github.com/polytypic/partial.lenses.git" | ||
"url": "git+https://github.com/dirty-js/partial.lenses.git" | ||
}, | ||
@@ -25,5 +25,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/polytypic/partial.lenses/issues" | ||
"url": "https://github.com/dirty-js/partial.lenses/issues" | ||
}, | ||
"homepage": "https://github.com/polytypic/partial.lenses#readme", | ||
"homepage": "https://github.com/dirty-js/partial.lenses#readme", | ||
"dependencies": { | ||
@@ -33,11 +33,11 @@ "ramda": "^0.19.1" | ||
"devDependencies": { | ||
"babel": "^6.3.13", | ||
"babel-cli": "^6.3.17", | ||
"babel-eslint": "^4.1.6", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.3.16", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-preset-stage-2": "^6.3.13", | ||
"eslint": "^1.10.3", | ||
"mocha": "^2.4.4" | ||
"babel": "^6.5.2", | ||
"babel-cli": "^6.5.1", | ||
"babel-eslint": "^4.1.8", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2", | ||
"babel-preset-es2015": "^6.5.0", | ||
"babel-preset-stage-2": "^6.5.0", | ||
"eslint": "^2.0.0", | ||
"mocha": "^2.4.5" | ||
} | ||
} |
145
README.md
@@ -6,9 +6,11 @@ [ [Examples](#examples) | [Reference](#reference) | [Background](#background) ] | ||
existing part of a data structure, a partial lens can *view* optional data, | ||
*insert* new data, *update* existing data and *delete* existing data. | ||
*insert* new data, *update* existing data and *delete* existing data and can | ||
provide *default* values and maintain *required* data structure parts. | ||
In Javascript, optional data can be mapped to `undefined`, which is what partial | ||
lenses also do. When the viewed part of a data structure is missing, the result | ||
is `undefined`. When a part of a data structure is set to `undefined`, the part | ||
is deleted. Partial lenses are defined in such a way that operations compose | ||
and one can conveniently and robustly operate on deeply nested data structures. | ||
In Javascript, missing data can be mapped to `undefined`, which is what partial | ||
lenses also do. When a part of a data structure is missing, an attempt to view | ||
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. | ||
Partial lenses are defined in such a way that operations compose and one can | ||
conveniently and robustly operate on deeply nested data structures. | ||
@@ -30,9 +32,9 @@ [![npm version](https://badge.fury.io/js/partial.lenses.svg)](http://badge.fury.io/js/partial.lenses) | ||
const textIn = language => | ||
L("contents", | ||
L.required([]), | ||
L.normalize(R.sortBy(R.prop("language"))), | ||
L.find(c => c.language === language), | ||
L.default({language}), | ||
"text", | ||
L.default("")) | ||
L.compose(L.prop("contents"), | ||
L.required([]), | ||
L.normalize(R.sortBy(R.prop("language"))), | ||
L.find(R.whereEq({language})), | ||
L.default({language}), | ||
L.prop("text"), | ||
L.default("")) | ||
``` | ||
@@ -104,2 +106,8 @@ | ||
For clarity, the code snippets in this section avoided some of the shorthands | ||
that this library supports. In particular, | ||
* `L.compose(...)` can be abbreviated as `L(...)`, | ||
* `L.prop(string)` can be abbreviated as `string`, and | ||
* `L.set(l, undefined, s)` can be abbreviated as `L.delete(l, s)`. | ||
## Reference | ||
@@ -119,4 +127,4 @@ | ||
* `L(l0, ...ls)` and `L.compose(l0, ...ls)` both are the same as | ||
`R.compose(lift(l0), ...ls.map(lift))` (see | ||
* `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)). | ||
@@ -132,2 +140,4 @@ * `L.lens(get, set)` is the same as `R.lens(get, set)` (see | ||
#### Lifting | ||
The idempotent `lift` operation is defined as | ||
@@ -145,3 +155,4 @@ | ||
and is available as a non-default export. | ||
and is available as a non-default export. All operations in this library that | ||
take lenses as arguments implicitly lift them. | ||
@@ -154,24 +165,51 @@ #### L.delete(l, s) | ||
#### L.firstOf(l0, ...ls) | ||
### 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`. | ||
In alphabetical order. | ||
Note that `L.firstOf` is an associative operation, but there is no identity | ||
element. | ||
#### L.append | ||
### Lenses | ||
`L.append` is a special lens that operates on arrays. The view of `L.append` is | ||
always undefined. Setting `L.append` to undefined has no effect by itself. | ||
Setting `L.append` to a defined value appends the value to the end of the | ||
focused array. | ||
#### L.prop(string) | ||
#### L.choose(maybeValue => PartialLens) | ||
`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 | ||
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. | ||
`L.choose(maybeValue => PartialLens)` creates a lens whose operation is | ||
determined by the given function that maps the underlying view, which can be | ||
undefined, to a lens. | ||
#### L.filter(predicate) | ||
`L.filter(predicate)` operates on arrays. When viewed, only elements matching | ||
the given predicate will be returned. When set, the resulting array will be | ||
formed by concatenating the set array and the complement of the filtered | ||
context. If the resulting array would be empty, the whole result will be | ||
undefined. | ||
*Note:* An alternative design for filter could implement a smarter algorithm to | ||
combine arrays when set. For example, an algorithm based on | ||
[edit distance](https://en.wikipedia.org/wiki/Edit_distance) could be used to | ||
maintain relative order of elements. While this would not be difficult to | ||
implement, it doesn't seem to make sense, because in most cases use of | ||
`normalize` would be preferable. | ||
#### L.find(value => boolean) | ||
`L.find(value => boolean)` 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 predicate. When no matching element is found the effect is | ||
same as with `L.append`. | ||
#### L.firstOf(l, ...ls) | ||
`L.firstOf(l, ...ls)` returns a partial lens that acts like the first of the | ||
given lenses, `l, ...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 | ||
`l`. | ||
Note that `L.firstOf` is an associative operation, but there is no identity | ||
element. | ||
#### L.index(integer) | ||
@@ -189,13 +227,6 @@ | ||
#### L.find(predicate) | ||
#### L.normalize(value => value) | ||
`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` with the index set to the length of the array. | ||
#### L.normalize(transform) | ||
`L.normalize(transform)` maps the value with same given `transform` when viewed | ||
and set and implicitly maps undefined to undefined. More specifically, | ||
`L.normalize(value => value)` maps the value with same given transform when | ||
viewed and set and implicitly maps undefined to undefined. More specifically, | ||
`L.normalize(transform)` is equivalent to `R.lens(toPartial(transform), | ||
@@ -208,6 +239,16 @@ toPartial(transform))` where | ||
The use case for `normalize` is to make it easy to determine whether, after a | ||
change, the data has actually changed. By keeping the data normalized, a simple | ||
`R.equals` comparison will do. | ||
The main use case for `normalize` is to make it easy to determine whether, after | ||
a change, the data has actually changed. By keeping the data normalized, a | ||
simple `R.equals` comparison will do. | ||
#### L.prop(string) | ||
`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 | ||
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. | ||
#### L.replace(inn, out) | ||
@@ -219,5 +260,5 @@ | ||
The use case for `replace` is to handle optional and required properties and | ||
elements. In most cases, rather than using `replace`, you will make selective | ||
use of `required` and `default`: | ||
The main use case for `replace` is to handle optional and required properties | ||
and elements. In most cases, rather than using `replace`, you will make | ||
selective use of `default` and `required`: | ||
@@ -228,2 +269,6 @@ ##### L.default(out) | ||
##### L.define(value) | ||
`L.define(value)` is the same as `L(L.required(value), L.default(value))`. | ||
##### L.required(inn) | ||
@@ -233,6 +278,2 @@ | ||
##### L.define(value) | ||
`L.define(value)` is the same as `L(L.required(value), L.default(value))`. | ||
## Background | ||
@@ -239,0 +280,0 @@ |
@@ -41,7 +41,6 @@ import R from "ramda" | ||
const conserve = f => (n0, o) => { | ||
const n = f(n0, o) | ||
return R.equals(n, o) ? o : n | ||
} | ||
const conserve = (c0, c1) => R.equals(c0, c1) ? c0 : c1 | ||
const toConserve = f => (y, c0) => conserve(c0, f(y, c0)) | ||
// | ||
@@ -67,27 +66,15 @@ | ||
L.firstOf = (l0, ...ls) => { | ||
l0 = lift(l0) | ||
L.choose = x2yL => toFunctor => target => { | ||
const l = lift(x2yL(target)) | ||
return R.map(focus => R.set(l, focus, target), toFunctor(R.view(l, target))) | ||
} | ||
if (ls.length === 0) | ||
return l0 | ||
L.firstOf = (l, ...ls) => L.choose(x => { | ||
const lls = [l, ...ls] | ||
return lls[Math.max(0, lls.findIndex(l => L.view(l, x) !== undefined))] | ||
}) | ||
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) | ||
} | ||
if (undefined === r) | ||
l = l0 | ||
return R.map(focus => R.set(l, focus, target), toFunctor(r)) | ||
} | ||
} | ||
L.replace = R.curry((inn, out) => | ||
R.lens(x => R.equals(x, inn) ? out : x, | ||
conserve(y => R.equals(y, out) ? inn : y))) | ||
toConserve(y => R.equals(y, out) ? inn : y))) | ||
@@ -99,3 +86,3 @@ L.default = L.replace(undefined) | ||
L.normalize = transform => | ||
R.lens(toPartial(transform), conserve(toPartial(transform))) | ||
R.lens(toPartial(transform), toConserve(toPartial(transform))) | ||
@@ -106,20 +93,9 @@ L.prop = k => | ||
L.find = predicate => R.lens(xs => xs && xs.find(predicate), (x, xs) => { | ||
if (x === undefined) { | ||
if (xs === undefined) | ||
return undefined | ||
const i = xs.findIndex(predicate) | ||
if (i < 0) | ||
return xs | ||
return dropped(xs.slice(0, i).concat(xs.slice(i+1))) | ||
} else { | ||
if (xs === undefined) | ||
return [x] | ||
const i = xs.findIndex(predicate) | ||
if (i < 0) | ||
return xs.concat([x]) | ||
if (R.equals(x, xs[i])) | ||
return xs | ||
return xs.slice(0, i).concat([x], xs.slice(i+1)) | ||
} | ||
L.find = predicate => L.choose(xs => { | ||
if (xs === undefined) | ||
return L.append | ||
const i = xs.findIndex(predicate) | ||
if (i < 0) | ||
return L.append | ||
return L.index(i) | ||
}) | ||
@@ -145,2 +121,16 @@ | ||
L.append = R.lens(() => {}, (x, xs) => { | ||
if (x === undefined) { | ||
return xs | ||
} else { | ||
if (xs === undefined) | ||
return [x] | ||
else | ||
return 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 default L |
@@ -15,4 +15,4 @@ import R from "ramda" | ||
const testEq = (expr, fn, expect) => it(`${expr} => ${show(expect)}`, () => { | ||
const actual = fn() | ||
const testEq = (expr, expect) => it(`${expr} => ${show(expect)}`, () => { | ||
const actual = eval(`(L, R) => ${expr}`)(L, R) | ||
if (!R.equals(actual, expect)) | ||
@@ -23,135 +23,79 @@ throw new Error(`Expected: ${show(expect)}, actual: ${show(actual)}`) | ||
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) | ||
testEq('L.compose.length', 1) | ||
testEq('L.default.length', 1) | ||
testEq('L.define.length', 1) | ||
testEq('L.delete.length', 2) | ||
testEq('L.find.length', 1) | ||
testEq('L.index.length', 1) | ||
testEq('L.length', 1) | ||
testEq('L.lens.length', 2) | ||
testEq('L.normalize.length', 1) | ||
testEq('L.over.length', 3) | ||
testEq('L.prop.length', 1) | ||
testEq('L.replace.length', 2) | ||
testEq('L.required.length', 1) | ||
testEq('L.set.length', 3) | ||
testEq('L.view.length', 2) | ||
}) | ||
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])', () => | ||
L.set(L.find(R.equals(2)), undefined, [1, 2, 3]), [1, 3]) | ||
testEq('L.set(L.find(R.equals(2)), 4, [1, 2, 3])', () => | ||
L.set(L.find(R.equals(2)), 4, [1, 2, 3]), [1, 4, 3]) | ||
testEq('L.set(L.find(R.equals(2)), 2, [1, 4, 3])', () => | ||
L.set(L.find(R.equals(2)), 2, [1, 4, 3]), [1, 4, 3, 2]) | ||
testEq('L.set(L.find(R.equals(2)), 2, undefined)', () => | ||
L.set(L.find(R.equals(2)), 2, undefined), [2]) | ||
testEq('L.set(L.find(R.equals(2)), 2, [])', () => | ||
L.set(L.find(R.equals(2)), 2, []), [2]) | ||
testEq('L.view(L.find(R.equals(2)), undefined)', () => | ||
L.view(L.find(R.equals(2)), undefined), undefined) | ||
testEq('L.view(L.find(R.equals(2)), [3])', () => | ||
L.view(L.find(R.equals(2)), [3]), undefined) | ||
testEq('L.set(L.find(R.equals(2)), undefined, [,,2])', undefined) | ||
testEq('L.set(L.find(R.equals(2)), undefined, [1, 2, 3])', [1, 3]) | ||
testEq('L.set(L.find(R.equals(2)), 4, [1, 2, 3])', [1, 4, 3]) | ||
testEq('L.set(L.find(R.equals(2)), 2, [1, 4, 3])', [1, 4, 3, 2]) | ||
testEq('L.set(L.find(R.equals(2)), 2, undefined)', [2]) | ||
testEq('L.set(L.find(R.equals(2)), 2, [])', [2]) | ||
testEq('L.view(L.find(R.equals(2)), undefined)', undefined) | ||
testEq('L.view(L.find(R.equals(2)), [3])', undefined) | ||
}) | ||
describe('L.index', () => { | ||
testEq('L.set(L(1), undefined, [,,])', () => | ||
L.set(L(1), undefined, [,,]), undefined) | ||
testEq('L.set(L.compose(L.required([]), 1), undefined, [,,])', () => | ||
L.set(L.compose(L.required([]), 1), undefined, [,,]), []) | ||
testEq('L.set(L(1), 4, [1, 2, 3])', () => | ||
L.set(L(1), 4, [1, 2, 3]), [1, 4, 3]) | ||
testEq('L.set(2, 4, undefined)', () => | ||
L.set(2, 4, undefined), [,, 4]) | ||
testEq('L.set(L(2), 4, [1])', () => | ||
L.set(L(2), 4, [1]), [1,, 4]) | ||
testEq('L.delete(L(0), [1, 2, 3])', () => | ||
L.delete(L(0), [1, 2, 3]), [2, 3]) | ||
testEq('L.set(L(1), undefined, [1, 2, 3])', () => | ||
L.set(L(1), undefined, [1, 2, 3]), [1, 3]) | ||
testEq('L.set(2, undefined, [1, 2, 3])', () => | ||
L.set(2, undefined, [1, 2, 3]), [1, 2]) | ||
testEq('L.set(L(5), undefined, [1, 2, 3])', () => | ||
L.set(L(5), undefined, [1, 2, 3]), [1, 2, 3]) | ||
testEq('L.view(5, undefined)', () => | ||
L.view(5, undefined), undefined) | ||
testEq('L.view(L(5), [1, 2, 3])', () => | ||
L.view(L(5), [1, 2, 3]), undefined) | ||
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(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(2, undefined, [1, 2, 3])', [1, 2]) | ||
testEq('L.set(L(5), undefined, [1, 2, 3])', [1, 2, 3]) | ||
testEq('L.view(5, undefined)', undefined) | ||
testEq('L.view(L(5), [1, 2, 3])', undefined) | ||
}) | ||
describe('L.prop', () => { | ||
testEq('L.set(L("x"), undefined, {x: 1})', () => | ||
L.set(L("x"), undefined, {x: 1}), undefined) | ||
testEq('L.set(L("x", L.required(null)), undefined, {x: 1})', () => | ||
L.set(L("x", L.required(null)), undefined, {x: 1}), {x: null}) | ||
testEq('L.set(L.compose("x", L.required(null)), 2, {x: 1})', () => | ||
L.set(L.compose("x", L.required(null)), 2, {x: 1}), {x: 2}) | ||
testEq('L.delete("y", {x: 1, y: 2})', () => | ||
L.delete("y", {x: 1, y: 2}), {x: 1}) | ||
testEq('L.set(L("y"), 3, {x: 1, y: 2})', () => | ||
L.set(L("y"), 3, {x: 1, y: 2}), {x: 1, y: 3}) | ||
testEq('L.set("z", 3, {x: 1, y: 2})', () => | ||
L.set("z", 3, {x: 1, y: 2}), {x: 1, y: 2, z: 3}) | ||
testEq('L.set(L("z"), 3, undefined)', () => | ||
L.set(L("z"), 3, undefined), {z: 3}) | ||
testEq('L.view("z", undefined)', () => | ||
L.view("z", undefined), undefined) | ||
testEq('L.view(L("z"), {x: 1})', () => | ||
L.view(L("z"), {x: 1}), undefined) | ||
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("z", 3, {x: 1, y: 2})', {x: 1, y: 2, z: 3}) | ||
testEq('L.set(L("z"), 3, undefined)', {z: 3}) | ||
testEq('L.view("z", undefined)', undefined) | ||
testEq('L.view(L("z"), {x: 1})', undefined) | ||
}) | ||
describe("L.replace", () => { | ||
testEq('L.view(L.replace(undefined, ""), undefined)', () => | ||
L.view(L.replace(undefined, ""), undefined), "") | ||
testEq('L.view(L.replace(undefined, ""), "defined")', () => | ||
L.view(L.replace(undefined, ""), "defined"), "defined") | ||
testEq('L.set(L.replace(undefined, ""), "", "anything")', () => | ||
L.set(L.replace(undefined, ""), "", "anything"), undefined) | ||
testEq('L.set(L.replace(undefined, ""), "defined", "anything")', () => | ||
L.set(L.replace(undefined, ""), "defined", "anything"), "defined") | ||
testEq('L.view(L.replace(undefined, ""), undefined)', "") | ||
testEq('L.view(L.replace(undefined, ""), "defined")', "defined") | ||
testEq('L.set(L.replace(undefined, ""), "", "anything")', undefined) | ||
testEq('L.set(L.replace(undefined, ""), "defined", "anything")', "defined") | ||
}) | ||
describe("L.default", () => { | ||
testEq('L.view(L.default(""), undefined)', () => | ||
L.view(L.default(""), undefined), "") | ||
testEq('L.view(L.default(""), "defined")', () => | ||
L.view(L.default(""), "defined"), "defined") | ||
testEq('L.set(L.default(""), "", "anything")', () => | ||
L.set(L.default(""), "", "anything"), undefined) | ||
testEq('L.set(L.default(""), "defined", "anything")', () => | ||
L.set(L.default(""), "defined", "anything"), "defined") | ||
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.normalize", () => { | ||
testEq('L.view(L.normalize(R.sortBy(R.identity)), [1,3,2,5])', () => | ||
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])', () => | ||
L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), 4, [1,3,2,5]), | ||
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])', | ||
[1,3,4,5]) | ||
testEq('L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), 4, undefined)', () => | ||
L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), 4, undefined), | ||
testEq('L.set(L(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])', () => | ||
L.delete(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), [2]), | ||
testEq('L.delete(L(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])', () => | ||
L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), undefined, [1,3,2,5]), | ||
testEq('L.set(L(L.normalize(R.sortBy(R.identity)), L.find(R.equals(2))), undefined, [1,3,2,5])', | ||
[1,3,5]) | ||
@@ -161,22 +105,22 @@ }) | ||
describe("L.firstOf", () => { | ||
testEq('L.view(L.firstOf("x", "y"), {x: 11, y: 12})', () => | ||
L.view(L.firstOf("x", "y"), {x: 11, y: 12}), 11) | ||
testEq('L.view(L.firstOf("y", "x"), {x: 11, y: 12})', () => | ||
L.view(L.firstOf("y", "x"), {x: 11, y: 12}), 12) | ||
testEq('L.view(L.firstOf("x", "y"), {z: 13})', () => | ||
L.view(L.firstOf("x", "y"), {z: 13}), undefined) | ||
testEq('L.over(L.firstOf("x", "y"), x => x-2, {x: 11, y: 12})', () => | ||
L.over(L.firstOf("x", "y"), x => x-2, {x: 11, y: 12}), {x: 9, y: 12}) | ||
testEq('L.over(L.firstOf("y", "x"), x => x-2, {x: 11, y: 12})', () => | ||
L.over(L.firstOf("y", "x"), x => x-2, {x: 11, y: 12}), {x: 11, y: 10}) | ||
testEq('L.set(L.firstOf("x", "y"), 12, {z: 13})', () => | ||
L.set(L.firstOf("x", "y"), 12, {z: 13}), {x: 12, z: 13}) | ||
testEq('L.set(L.firstOf("y", "x"), 12, {z: 13})', () => | ||
L.set(L.firstOf("y", "x"), 12, {z: 13}), {y: 12, z: 13}) | ||
testEq('L.delete(L.firstOf("x", "y"), {z: 13})', () => | ||
L.delete(L.firstOf("x", "y"), {z: 13}), {z: 13}) | ||
testEq('L.delete(L.firstOf("x", "y"), {x: 11, y: 12})', () => | ||
L.delete(L.firstOf("x", "y"), {x: 11, y: 12}), {y: 12}) | ||
testEq('L.delete(L.firstOf("y", "x"), {x: 11, y: 12})', () => | ||
L.delete(L.firstOf("y", "x"), {x: 11, y: 12}), {x: 11}) | ||
testEq('L.view(L.firstOf("x", "y"), {x: 11, y: 12})', 11) | ||
testEq('L.view(L.firstOf("y", "x"), {x: 11, y: 12})', 12) | ||
testEq('L.view(L.firstOf("x", "y"), {z: 13})', undefined) | ||
testEq('L.over(L.firstOf("x", "y"), x => x-2, {x: 11, y: 12})', {x: 9, y: 12}) | ||
testEq('L.over(L.firstOf("y", "x"), x => x-2, {x: 11, y: 12})', {x: 11, y: 10}) | ||
testEq('L.set(L.firstOf("x", "y"), 12, {z: 13})', {x: 12, z: 13}) | ||
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}) | ||
}) | ||
describe("L.filter", () => { | ||
testEq('L.view(L.filter(R.lt(9)), [3,1,4,1,5,9,2])', []) | ||
testEq('L.view(L.filter(R.lt(2)), undefined)', undefined) | ||
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.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]) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
321
46056
382
2