Advertisement
Guest User

Reducing boilerplat in chaining pattern

a guest
Mar 23rd, 2018
92
0
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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement