4 ms·
That's not plain Javascript. That's Lodash through and through. The array transformation methods built into Javascript run to completion after every step buildi
by webstrand 5y ago
That's not plain Javascript. That's Lodash through and through. The array transformation methods built into Javascript run to completion after every step building multiple copies of the array as each transformation is applied. Lodash's chain and related methods do not make multiple copies of the array during transformation.
- bunnyfoofoo 5y agoHey, do you have more documentation on how vanilla Javascript handles array transformations? As an example: array.filter(f => true).map(f => f); My understanding is that filter creates a new array, then maps that new array to another new array in final step. Does lodash do something differently? I'm not seeing anything in documentation for _.chain that says it does something differently.
- eurasiantiger 5y agoIt’s best to avoid _.chain, see https://medium.com/bootstart/why-using-chain-is-a-mistake-9bc1f80d51ba https://medium.com/bootstart/why-using-chain-is-a-mistake-9b...
- e12e 5y agoHow so? Looks like filter builds a new array, and so does map? And both while-loops over the entire input? https://github.com/lodash/lodash/blob/master/filter.js https://github.com/lodash/lodash/blob/master/filter.js https://github.com/lodash/lodash/blob/master/map.js https://github.com/lodash/lodash/blob/master/map.js With a quick search I found this: https://hackernoon.com/es6-lodash-native-javascript-nodejs-example-tutorial-map-function-functional-programming-performance-speed-69645e613049 https://hackernoon.com/es6-lodash-native-javascript-nodejs-e... Which seems to indicate little difference?
- rco8786 5y agoI mean the continuation pattern used that effectively mimics the pipe operator. I realize that the functions themselves are provided by lodash.