@@ -388,8 +388,6 @@ Precedents include:
388
388
389
389
[ lodash.identity ] : https://www.npmjs.com/package/lodash.identity
390
390
391
- ## Function.tap
392
- The ` Function.tap ` static method creates a new unary function
393
391
## Function.noop
394
392
395
393
The ` Function.noop ` static method always returns undefined.
@@ -558,39 +556,47 @@ Precedents include:
558
556
559
557
[ lodash.throttle ] : https://www.npmjs.com/package/lodash.debounce
560
558
559
+ ## Function.prototype.aside
560
+ The ` Function.prototype.aside ` method creates a new unary function
561
561
that applies some callback to its argument before returning the original argument.
562
562
563
563
``` js
564
- Function . tap (callback );
564
+ fn . aside ( );
565
565
566
- const { tap } = Function ;
566
+ const { aside } = Function ;
567
567
568
- tap ( console .log ) (5 ); // Prints 5 before returning 5.
568
+ console .log . aside (5 ); // Prints 5 before returning 5.
569
569
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`.
571
572
572
573
const data = await Promise .resolve (' intro.txt' )
573
574
.then (Deno .open )
574
575
.then (Deno .readAll )
575
- .then (tap ( console .log ))
576
+ .then (console .log . aside ( ))
576
577
.then (data => new TextDecoder (' utf-8' ).decode (data));
578
+ ```
577
579
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.
586
581
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 ();
594
600
}
595
601
` ` `
596
602
0 commit comments