Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit ae051b0

Browse files
committed
explainer: Rename § tap to § aside
See #8.
1 parent 7207a06 commit ae051b0

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,6 @@ Precedents include:
388388

389389
[lodash.identity]: https://www.npmjs.com/package/lodash.identity
390390

391-
## Function.tap
392-
The `Function.tap` static method creates a new unary function
393391
## Function.noop
394392

395393
The `Function.noop` static method always returns undefined.
@@ -558,39 +556,47 @@ Precedents include:
558556

559557
[lodash.throttle]: https://www.npmjs.com/package/lodash.debounce
560558

559+
## Function.prototype.aside
560+
The `Function.prototype.aside` method creates a new unary function
561561
that applies some callback to its argument before returning the original argument.
562562

563563
```js
564-
Function.tap(callback);
564+
fn.aside();
565565

566-
const { tap } = Function;
566+
const { aside } = Function;
567567

568-
tap(console.log)(5); // Prints 5 before returning 5.
568+
console.log.aside(5); // Prints 5 before returning 5.
569569

570-
arr.map(tap(console.log)).map(f); // Prints each item from `arr` before passing them to `f`.
570+
arr.map(console.log.aside).map(f);
571+
// Prints each item from `arr` before passing them to `f`.
571572

572573
const data = await Promise.resolve('intro.txt')
573574
.then(Deno.open)
574575
.then(Deno.readAll)
575-
.then(tap(console.log))
576+
.then(console.log.aside())
576577
.then(data => new TextDecoder('utf-8').decode(data));
578+
```
577579

578-
// From [email protected]/src/constructor.js
579-
var fakeConstructorFromNames = (funcNames) => {
580-
return tap(tdFunction('(unnamed constructor)'), (fakeConstructor) => {
581-
_.each(funcNames, (funcName) => {
582-
fakeConstructor.prototype[funcName] = tdFunction(`#${String(funcName)}`)
583-
})
584-
})
585-
}
580+
The following real-world example originally used [lodash][].aside and lodash/fp’s pipe.
586581

587-
// From <https://github.com/rendrjs/rendr/blob/1.1.4/test/shared/fetcher.test.js>
588-
function getModelResponse(version, id, addJsonKey) {
589-
if (addJsonKey) {
590-
return tap({}, function(obj) {
591-
obj.listing = resp;
592-
});
593-
}
582+
```js
583+
// From IBM/report-toolkit v0.6.1 packages/common/src/config.js
584+
export function filterEnabledRules(config) {
585+
return pipe(
586+
config,
587+
_.getOr({}, 'rules'),
588+
_.toPairs,
589+
_.reduce(
590+
(enabledRules, [ruleName, ruleConfig]) =>
591+
(_.isObject(ruleConfig) && _.get('enabled', ruleConfig)) ||
592+
(_.isBoolean(ruleConfig) && ruleConfig)
593+
? [ruleName, ...enabledRules]
594+
: enabledRules,
595+
[]
596+
),
597+
(ruleIds => {
598+
debug('found %d enabled rule(s)', ruleIds.length);
599+
}).aside();
594600
}
595601
```
596602

0 commit comments

Comments
 (0)