converge
makes a lot of sense as a name
['FY', 'Q3', 'Q2'] => {'FY': [ some filtered stuff here], 'Q3': [ 'some other stuff' ], 'Q2': [ ]}
Use case is when getting some stuff from SQL and transforming into more json like structure
fromPairs
?
converge
as a name. I do think useWith
would have to be renamed as it can mean anything. How about converge
("To come together from different directions") and disperse
("To strew or distribute widely")? The two words are related because they're kind of opposite, but they also both say something about what happens to the arguments. Besides, I think the subtle differences between the two are too great to name them after the same thing. I'm specifically talking about how the arity for the returned functions is chosen. For converge
it will be the biggest arity of all given transformers, and for useWith
it will be equal to the amount of given transformers.
// input
var input = {
apple: 3,
cucumber: 1
};
// desired output
[{
name: 'apple',
quantity: 3
}, {
name: 'cucumber',
quantity: 1
}];
function transformData(content) {
return reduce(function(output, key) {
output.push({
name: key,
quantity: content[key]
});
return output;
}, [], Object.keys(content));
}
var transformData = R.pipe(R.toPairs, R.map(R.zipObj(["name", "quantity"])))
- http://bit.ly/1QfI7WH
disperse
, the more I like it! Converge "converges" the arguments with every given transformer, and disperse "disperses" the arguments across all given transformers! :D .. Maybe I'm falling in love, and I should kill my darlings and such.. It's a good name right? :worried:
converge
and useWith
necessarily disperse first, converge
dispersing the entirety of arguments
to all transformers and useWith
dispersing individual arguments to individual transformers. So it's a little unclear from that perspective, I think. It's still better than useWith
to describe the behaviour at least.
useWith
's new name would be helpful, considering "spread" is used with similar meaning by Q (and other promise libraries?).
R.spread
sounds like an alias to R.apply
(which is really what it means in Q and such too), so you would have to come up with a function name containing "spread", which might get long.
convergeSpread
was the most logical name based on that, and it really is very long. :smile:
convergeSpread
makes it seem like it sub-categorizes converge
behavior-wise, which it doesn't because the arity of the resulting function is decided in a completely different manner.
converge
. It seemed an improvement on the original fork
. But useWith
has always been a placeholder in my mind, filling the space until we could arrive at a good name.
diverge
is not bad, as long as we don't make to much of its connection with converge
. The two words describe well different parts of the operation, and in actuality the way the word 'converge' fits would equally fit useWith
.
ppipe
chain of simple functions that I can test with straight function application.
ppipe
-esque function in my current project too. But shouldn't you still be passing promises to the pipeline to test it?
plift
returns a value synchronously when you only pass regular values to the function in the first place. So the whole pipeline stays synchronous if you never use a promise, gotcha.
plift
and such I suppose it doesn't actually matter.
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.
rewire
or something to replace it with mock implementation?
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.
converge
. The focus there is on the individual functions, and not on the one that combines the results. As I said, it's just a matter of focus... and of course, a matter of opinion.
useWith
(aka modArgs
) in ld land
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
and modArgsSet
disperse
. It seems that converge
is already pretty well accepted.
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.
(payload, templateSource) =>
or something like that, and if the second argument's not passed you can use readTemplates
as the source?