SHARE
TWEET

Reducing boilerplat in chaining pattern

a guest Mar 23rd, 2018 21 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const myFunctions = {
  2.   'filter': predicate => function*() {
  3.     for (const item of this) {
  4.       if (predicate(item)) {
  5.         yield item;
  6.       }
  7.     }
  8.   },
  9.   'map': mapper => function*() { /* ... */ }
  10. };
  11.  
  12. for (const fun of Object.keys(myFunctions)) {
  13.   List.prototype[fun] = function (...args) {
  14.     return new List(myFunctions[fun].apply(this, args));
  15.   };
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top