Skip to content

Commit

Permalink
Fixed setPath and updatePath not returning unary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ascartabelli committed Mar 9, 2018
1 parent 31319be commit a547846
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
12 changes: 8 additions & 4 deletions dist/lamb.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @overview lamb - A lightweight, and docile, JavaScript library to help embracing functional programming.
* @author Andrea Scartabelli <andrea.scartabelli@gmail.com>
* @version 0.55.0-alpha.1
* @version 0.55.0-alpha.3
* @module lamb
* @license MIT
* @preserve
Expand Down Expand Up @@ -46,7 +46,7 @@
* @since 0.53.0
* @type String
*/
"@@lamb/version": {value: "0.55.0-alpha.1"}
"@@lamb/version": {value: "0.55.0-alpha.3"}
});

// prototype shortcuts
Expand Down Expand Up @@ -3436,7 +3436,9 @@
* @returns {Function}
*/
function setPath (path, value, separator) {
return partialRight(setPathIn, [path, value, separator]);
return function (source) {
return setPathIn(source, path, value, separator);
};
}

/**
Expand Down Expand Up @@ -3637,7 +3639,9 @@
* @returns {Function}
*/
function updatePath (path, updater, separator) {
return partialRight(updatePathIn, [path, updater, separator]);
return function (source) {
return updatePathIn(source, path, updater, separator);
};
}

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/lamb.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lamb.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"coveralls": "gulp coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"tonicExample": "var _ = require('lamb');",
"version": "0.55.0-alpha.2",
"version": "0.55.0-alpha.3",
"devDependencies": {
"coveralls": "^3.0.0",
"gulp": "^3.9.1",
Expand Down
8 changes: 6 additions & 2 deletions src/accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ var setKey = _makePartial3(setIn);
* @returns {Function}
*/
function setPath (path, value, separator) {
return partialRight(setPathIn, [path, value, separator]);
return function (source) {
return setPathIn(source, path, value, separator);
};
}

/**
Expand Down Expand Up @@ -559,7 +561,9 @@ var updateKey = _makePartial3(updateIn);
* @returns {Function}
*/
function updatePath (path, updater, separator) {
return partialRight(updatePathIn, [path, updater, separator]);
return function (source) {
return updatePathIn(source, path, updater, separator);
};
}

/**
Expand Down
30 changes: 30 additions & 0 deletions test/spec/accessorsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,21 @@ describe("lamb.accessors", function () {
expect(lamb.setPathIn(obj, "b.a.g", 99)).toEqual(r);
});

it("should ignore extra arguments passed to the built function in its partially applied form", function () {
var r = lamb.setPath("b.c", "bar")(obj, {});

expect(r).toEqual({
a: 2,
b: {
a: {g: 10, h: 11},
b: [4, 5],
c: "bar",
d: [, 55, ,] // eslint-disable-line comma-spacing, no-sparse-arrays
},
"c.d": {"e.f": 6}
});
});

it("should allow custom separators", function () {
var r = lamb.setPath("c.d->e.f", 99, "->")(obj);

Expand Down Expand Up @@ -1233,6 +1248,21 @@ describe("lamb.accessors", function () {
expect(lamb.updatePathIn(obj, "b.a.g", double)).toEqual(r);
});

it("should ignore extra arguments passed to the built function in its partially applied form", function () {
var r = lamb.updatePath("b.a.h", double)(obj, {});

expect(r).toEqual({
a: 2,
b: {
a: {g: 10, h: 22},
b: [4, 5],
c: "foo",
d: [, 55, ,] // eslint-disable-line comma-spacing, no-sparse-arrays
},
"c.d": {"e.f": 6}
});
});

it("should allow custom separators", function () {
var r = lamb.updatePath("c.d->e.f", double, "->")(obj);

Expand Down

0 comments on commit a547846

Please sign in to comment.