JSFiddle - React, Tailwind, and code Playground

by hutber

JavaScript

class Lazy {
  constructor() {
    this.funcs = [];
  }

  add() {
  console.info(arguments)
    this.funcs.push({
      func: arguments[0],
      arg:  arguments[1]
    });
    return this;
  }

  evaluate(target) {
    return target.map(i => this.funcs.reduce(
      (acc, cur) => {
        //console.info(acc, cur);
        //console.info(cur.func.call(null, i, cur.arg));
        return cur.func.call(null, i, cur.arg)
      })
    );
  }
}
const lazyClass = new Lazy();
     const jamie =  lazyClass
        .add(function timesTwo(a) { return a * 2; })
        .add(function plus(a, b) { return a + b; }, 1)
      .evaluate([1, 2, 3]);
      console.info(jamie);