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
.
@raine another options is to add another function, one that performs the algorithm, like @00Davo said:
baseAlgorithm = (read, payload) =>
read(payload.type, payload.site)
.then(buildEmailOptions(payload))
.then(transporter.sendMailAsync.bind(transporter));
ioAlgorithm = (payload) =>
baseAlgorithm(readTemplates, payload);
module.exports = {baseAlgorithm, ioAlgorithm};
Then you can test the algorithm with a unit test, and the io version with an integration test.
input is
['apple', 'the', 'one', 'two', 'three', 'elephant', 'whatever']
var filterByLength = R.filter(function(str) {
return str.length > 3 && str.length < 6;
});
desired output is
['apple', 'three']