3 ms·
I’m just expanding the example in my mind, nothing arcane. And maybe it’_.s just me, but I _.fail to _.see how lodash _.is “cleaner”, or why “new” makes things
by wruza 5y ago
I’m just expanding the example in my mind, nothing arcane. And maybe it’_.s just me, but I _.fail to _.see how lodash _.is “cleaner”, or why “new” makes things dirty. Are we discussing The High Art of Source Code here? If yes, it ain’t my thing.
functional stdlib can be pretty clean, such as something like Stream(persons).filter(person => person.age > 18).map(person => person.firstName)
I see a stream object with at least a couple of methods, how is it functional? What does functional mean here, callbacks? I mean, array.filter(predicate) also takes one. If that’s the thing, nobody takes it away, it’s already natural to js, since it’s multiparadigm. And we already have piping, it looks like foo().bar().baz() or map(foo).filter(bar) or Object.keys().reduce(quux). If you want a class deconstructor for FP-101 code, here it is:
const fize = (name, …args) => (obj) => obj[name].apply(obj, args)
array.map(fize("toString", "hex"))
You can turn it into “fize.toString("hex")” with a little Proxy magic (still no chance for a type safety, sadly).
I understand the different approaches you propose, and I could even write some decent Haskell in my experimenting ages, but my main question is what problem do we solve here and how this solution would be functional and not “move methods to same-named pojos, write them explicitly and pretend it’s FP”.