Skip to content

Commit

Permalink
- renamed placeholder
Browse files Browse the repository at this point in the history
- updated tests and doc comments
  • Loading branch information
ascartabelli committed Feb 11, 2019
1 parent 68cd928 commit 383a698
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 120 deletions.
70 changes: 38 additions & 32 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.57.0-alpha.17
* @version 0.57.0-alpha.18
* @module lamb
* @license MIT
* @preserve
Expand All @@ -15,12 +15,14 @@
/**
* The placeholder object.
* @memberof module:lamb
* @alias module:lamb._
* @alias module:lamb.__
* @category Special properties
* @see {@link module:lamb.partial|partial}, {@link module:lamb.partialRight|partialRight}
* @see {@link module:lamb.asPartial|asPartial}
* @since 0.57.0
* @type {Object}
*/
var _ = {};
var __ = {};

/**
* Builds a function that returns a constant value.
Expand Down Expand Up @@ -140,17 +142,16 @@
}

/**
* Builds a partially applied function. The <code>lamb</code> object itself can be
* used as a placeholder argument and it's useful to alias it with a short symbol
* such as <code>_</code>.<br/>
* You can use a custom placeholder by setting the {@link module:lamb._|placeholder} property.
* Builds a partially applied function.<br/>
* The @link module:lamb.__|__} object can be used as a placeholder for arguments.<br/>
* @example
* var __ = _.__;
* var users = [
* {id: 1, name: "John", active: true, confirmedMail: true},
* {id: 2, name: "Jane", active: true, confirmedMail: false},
* {id: 3, name: "Mario", active: false, confirmedMail: false}
* ];
* var isKeyTrue = _.partial(_.hasKeyValue, [_, true]);
* var isKeyTrue = _.partial(_.hasKeyValue, [__, true]);
* var isActive = isKeyTrue("active");
* var hasConfirmedMail = isKeyTrue("confirmedMail");
*
Expand All @@ -163,7 +164,7 @@
* @see {@link module:lamb.asPartial|asPartial}
* @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}
* @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}
* @see {@link module:lamb._|_} The placeholder property.
* @see {@link module:lamb.__|__} The placeholder object.
* @since 0.1.0
* @param {Function} fn
* @param {Array} args
Expand All @@ -181,7 +182,7 @@

for (var i = 0, boundArg; i < argsLen; i++) {
boundArg = args[i];
newArgs[i] = boundArg === _ ? arguments[lastIdx++] : boundArg;
newArgs[i] = boundArg === __ ? arguments[lastIdx++] : boundArg;
}

for (var len = arguments.length; lastIdx < len; lastIdx++) {
Expand All @@ -207,7 +208,7 @@
return function (a, b) {
var f = shouldAritize && arguments.length !== 2 ? binary(fn) : fn;

return partial(f, [_, a, b]);
return partial(f, [__, a, b]);
};
}

Expand Down Expand Up @@ -518,8 +519,9 @@
*
* @example
* <caption>Explaining placeholder substitutions:</caption>
* var f1 = _.partial(_.list, ["a", _, _, "d"]);
* var f2 = _.partialRight(_.list, ["a", _, _, "d"]);
* var __ = _.__;
* var f1 = _.partial(_.list, ["a", __, __, "d"]);
* var f2 = _.partialRight(_.list, ["a", __, __, "d"]);
*
* f1("b", "c", "e") // => ["a", "b", "c", "d", "e"]
* f2("b", "c", "e") // => ["b", "a", "c", "e", "d"]
Expand All @@ -530,7 +532,7 @@
* @see {@link module:lamb.asPartial|asPartial}
* @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}
* @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}
* @see {@link module:lamb._|_} The placeholder property.
* @see {@link module:lamb.__|__} The placeholder object.
* @param {Function} fn
* @param {Array} args
* @since 0.52.0
Expand All @@ -549,7 +551,7 @@

for (var i = argsLen - 1, boundArg; i > -1; i--) {
boundArg = args[i];
boundArgs[i] = boundArg === _ ? arguments[lastIdx--] : boundArg;
boundArgs[i] = boundArg === __ ? arguments[lastIdx--] : boundArg;
}

for (i = 0; i <= lastIdx; i++) {
Expand Down Expand Up @@ -1801,7 +1803,7 @@
* @param {ArrayLike} arrayLike
* @returns {Array}
*/
var init = partial(slice, [_, 0, -1]);
var init = partial(slice, [__, 0, -1]);

/**
* Inserts the provided element in a copy of an array-like object at the
Expand Down Expand Up @@ -2764,7 +2766,7 @@
* @param {Function} [comparer] An optional custom comparer function.
* @returns {Sorter}
*/
var sorter = partial(_sorter, [_, false, _]);
var sorter = partial(_sorter, [__, false, __]);

/**
* Creates a descending sort criterion with the provided <code>reader</code> and
Expand All @@ -2784,7 +2786,7 @@
* @param {Function} [comparer] An optional custom comparer function.
* @returns {Sorter}
*/
var sorterDesc = partial(_sorter, [_, true, _]);
var sorterDesc = partial(_sorter, [__, true, __]);

/**
* Builds a partial application of {@link module:lamb.sort|sort} using the provided criteria.
Expand Down Expand Up @@ -2974,7 +2976,8 @@
/**
* Creates a pipeline of functions, where each function consumes the result of the previous one.
* @example
* var square = _.partial(Math.pow, [_, 2]);
* var __ = _.__;
* var square = _.partial(Math.pow, [__, 2]);
* var getMaxAndSquare = _.pipe([Math.max, square]);
*
* getMaxAndSquare(3, 5) // => 25
Expand Down Expand Up @@ -3108,7 +3111,7 @@
* @param {Function} updater
* @returns {Array}
*/
var updateIndex = partial(_setIndex, [_, _, null, _]);
var updateIndex = partial(_setIndex, [__, __, null, __]);

/**
* Builds a list of arrays out of the two given array-like objects by pairing items with
Expand Down Expand Up @@ -3224,21 +3227,21 @@

for (var i = 0, len = argsHolder.length, boundArg; i < len; i++) {
boundArg = argsHolder[i];
newArgs[i] = boundArg === _ && lastIdx < argsLen ? arguments[lastIdx++] : boundArg;
newArgs[i] = boundArg === __ && lastIdx < argsLen ? arguments[lastIdx++] : boundArg;
}

while (lastIdx < argsLen) {
newArgs[i++] = arguments[lastIdx++];
}

for (i = 0; i < argsLen; i++) {
if (arguments[i] === _) {
if (arguments[i] === __) {
return _asPartial(fn, newArgs);
}
}

for (i = 0, len = newArgs.length; i < len; i++) {
if (newArgs[i] === _) {
if (newArgs[i] === __) {
newArgs[i] = void 0;
}
}
Expand All @@ -3260,31 +3263,33 @@
* optional parameters as you can decide to apply the function even if its arity
* hasn't been entirely consumed.
* @example <caption>Explaining the function's behaviour:</caption>
* var __ = _.__;
* var f = _.asPartial(function (a, b, c) {
* return a + b + c;
* });
*
* f(4, 3, 2) // => 9
* f(4, _, 2)(3) // => 9
* f(_, 3, _)(4, _)(2) // => 9
* f(4, __, 2)(3) // => 9
* f(__, 3, __)(4, __)(2) // => 9
*
* @example <caption>Exploiting optional parameters:</caption>
* var __ = _.__;
* var f = _.asPartial(function (a, b, c) {
* return a + b + (c || 0);
* });
*
* var addFive = f(5, _);
* var addFive = f(5, __);
* addFive(2) // => 7
*
* var addNine = addFive(4, _);
* var addNine = addFive(4, __);
* addNine(11) // => 20
*
* @memberof module:lamb
* @category Function
* @see {@link module:lamb.partial|partial}, {@link module:lamb.partialRight|partialRight}
* @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}
* @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}
* @see {@link module:lamb._|_} The placeholder property.
* @see {@link module:lamb.__|__} The placeholder object.
* @since 0.36.0
* @param {Function} fn
* @returns {Function}
Expand Down Expand Up @@ -3705,19 +3710,20 @@
* @returns {Function}
*/
function invokerOn (target) {
return partial(_invoker, [[], _, target]);
return partial(_invoker, [[], __, target]);
}

/**
* Builds a function that allows to map over the received arguments before applying them
* to the original one.
* @example
* var __ = _.__;
* var sumArray = _.reduceWith(_.sum);
* var sumArgs = _.compose(sumArray, _.list);
*
* sumArgs(1, 2, 3, 4, 5) // => 15
*
* var square = _.partial(Math.pow, [_, 2]);
* var square = _.partial(Math.pow, [__, 2]);
* var sumSquares = _.mapArgs(sumArgs, square);
*
* sumSquares(1, 2, 3, 4, 5) // => 55
Expand Down Expand Up @@ -4940,7 +4946,7 @@
*/
function checker (predicate, message, keyPaths, pathSeparator) {
return function (obj) {
var getValues = partial(getPathIn, [obj, _, pathSeparator]);
var getValues = partial(getPathIn, [obj, __, pathSeparator]);

return predicate.apply(obj, map(keyPaths, getValues)) ? [] : [message, keyPaths];
};
Expand Down Expand Up @@ -6715,7 +6721,7 @@

// CORE

exports._ = _;
exports.__ = __;
exports.always = always;
exports.areSVZ = areSVZ;
exports.binary = binary;
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 license.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2018 Andrea Scartabelli <andrea.scartabelli@gmail.com>
Copyright (c) 2015-2019 Andrea Scartabelli <andrea.scartabelli@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"tonicExample": "var _ = require('lamb');",
"version": "0.57.0-alpha.17",
"version": "0.57.0-alpha.18",
"devDependencies": {
"babel-preset-import-export": "^1.0.2",
"coveralls": "^3.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/array/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from "../core/_";
import __ from "../core/__";
import partial from "../core/partial";
import slice from "../core/slice";

Expand All @@ -18,6 +18,6 @@ import slice from "../core/slice";
* @param {ArrayLike} arrayLike
* @returns {Array}
*/
var init = partial(slice, [_, 0, -1]);
var init = partial(slice, [__, 0, -1]);

export default init;
4 changes: 2 additions & 2 deletions src/array/sorter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from "../core/_";
import __ from "../core/__";
import partial from "../core/partial";
import _sorter from "../privates/_sorter";

Expand All @@ -20,6 +20,6 @@ import _sorter from "../privates/_sorter";
* @param {Function} [comparer] An optional custom comparer function.
* @returns {Sorter}
*/
var sorter = partial(_sorter, [_, false, _]);
var sorter = partial(_sorter, [__, false, __]);

export default sorter;
4 changes: 2 additions & 2 deletions src/array/sorterDesc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from "../core/_";
import __ from "../core/__";
import partial from "../core/partial";
import _sorter from "../privates/_sorter";

Expand All @@ -20,6 +20,6 @@ import _sorter from "../privates/_sorter";
* @param {Function} [comparer] An optional custom comparer function.
* @returns {Sorter}
*/
var sorterDesc = partial(_sorter, [_, true, _]);
var sorterDesc = partial(_sorter, [__, true, __]);

export default sorterDesc;
4 changes: 2 additions & 2 deletions src/array/updateIndex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from "../core/_";
import __ from "../core/__";
import partial from "../core/partial";
import _setIndex from "../privates/_setIndex";

Expand Down Expand Up @@ -26,6 +26,6 @@ import _setIndex from "../privates/_setIndex";
* @param {Function} updater
* @returns {Array}
*/
var updateIndex = partial(_setIndex, [_, _, null, _]);
var updateIndex = partial(_setIndex, [__, __, null, __]);

export default updateIndex;
9 changes: 0 additions & 9 deletions src/core/_.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/core/__.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* The placeholder object.
* @memberof module:lamb
* @alias module:lamb.__
* @category Special properties
* @see {@link module:lamb.partial|partial}, {@link module:lamb.partialRight|partialRight}
* @see {@link module:lamb.asPartial|asPartial}
* @since 0.57.0
* @type {Object}
*/
export default {};
Loading

0 comments on commit 383a698

Please sign in to comment.