converge
and useWith
are essentially the same. It comes down to one passes the transforms a single argument of the index of the transform and the other passes it all arguments. So I'm trying to come up with a common name that describes that (tough). I'll keep kicking it around.
Although I recognize that there's an abstraction where useWith
and converge
are quite similar, my mental models of them are so different that it's hard to think of them as even related, except in that they both offer extensions to the notion of compose
.
To me, useWith
is all about running transformations on each of the parameters before supplying them to the main function; the focus is clearly on the main function. But converge
is about running a number of functions against the same data, and then at the end, almost incidentally, combining their results; the focus is on the individual transformations.
Of course this is only a matter of perspective, and it's certainly no more or less valid than the notion that @jdalton is proposing based on potentially similar implementations. But it's interesting to realize how different such perspectives can be.
var assign = _.partial(_.modArgs(_.assign, Object), null);
@00Davo
Maybe make the usual source of the promise a default argument, and pass a replacement for it in unit tests.
It currently looks like this,
module.exports = (payload) =>
readTemplates(payload.type, payload.site)
.then(buildEmailOptions(payload))
.then(transporter.sendMailAsync.bind(transporter));
readTemplates
is the impure one. did you mean that in this case, readTemplates
would be passed as an argument to the exported function?
modArgs
modifying args, modArgsSet
modifying a set of args. It also shows their close relationship so woot. I don't dig the sS
bit of modArgsSet
or using Set
but it's short and gets the point across.
max
be const
. In the other I have to make it a let
. IMO this highlights the key difference between imperative and functional code. The first is a definition of what max
is. The second is a sequence of steps that ends of with max
having the correct value.
let map = function(f, args) {
let [x, ...xs] = args;
if (x === void 0) {
return [];
} else {
return [f(x)].concat([].slice.call(map(f, xs)));
}
};
let [x,...xs] = args
is avoided it would be nice...
slice
.