Explicit chaining with lodash doesn't apply shortcut fusion

人走茶凉 提交于 2019-12-24 07:03:52

问题


While working with lodash, I found that it applied shortcut fusion when I used implicit chaining.

$ node -e 'const _ = require("lodash"); _([1,2,3]).map(n => { console.log(n); return n }).find(n => n <= 1)'
1

But when I changed this snippet to use explicit chaining, it doesn't apply shortcut fusion.

$ node -e 'const _ = require("lodash"); _.chain([1,2,3]).map(n => { console.log(n); return n }).find(n => n <= 1).value()'
1
2
3

As you can see, a function passed to map was called three times instead of once, which indicates lodash didn't apply shortcut fusion.

From their document, shortcut fusion should seem to be applied in both cases.

  1. Is this an intended behavior?
  2. Where in the document do they explain this behavior if so?
  3. Is there any ways to apply shortcut fusion with explicit chaining?

I use lodash 4.17.5 on node.js v8.10.0.


回答1:


I found a ticket about this issue at their GitHub project.

It's unexpected but is what it is for now.



来源:https://stackoverflow.com/questions/49894215/explicit-chaining-with-lodash-doesnt-apply-shortcut-fusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!