admin管理员组文章数量:1328035
The Lodash documentation says that it supports lazy evaluation. From my testing, the below chain is being evaluated 100 times rather than 10. I'm using version 3.10.1.
_(_.range(100))
.map(function(x) {console.log(1); return x; })
.take(10)
.value()
You can see that we print to the console 100 times inside map
, rather than the 10 times I would have expected. Check out the problem here: /
What am I doing wrong? How can I make this evaluate lazily?
Update: This appears to be a regression in Lodash. I tested how this works across versions and came across the following results:
Version 2.4.2: 100 times /
Version 3.0.0: 10 times /
Version 3.9.0 10 times /
Version 3.10.0: 100 times /
The Lodash documentation says that it supports lazy evaluation. From my testing, the below chain is being evaluated 100 times rather than 10. I'm using version 3.10.1.
_(_.range(100))
.map(function(x) {console.log(1); return x; })
.take(10)
.value()
You can see that we print to the console 100 times inside map
, rather than the 10 times I would have expected. Check out the problem here: https://jsfiddle/07utwk6y/
What am I doing wrong? How can I make this evaluate lazily?
Update: This appears to be a regression in Lodash. I tested how this works across versions and came across the following results:
Version 2.4.2: 100 times https://jsfiddle/4Lq7z5xL/
Version 3.0.0: 10 times https://jsfiddle/fd6g6un5/
Version 3.9.0 10 times https://jsfiddle/ju8rppee/
Version 3.10.0: 100 times https://jsfiddle/x1g13oo8/
Share Improve this question edited Aug 12, 2015 at 22:49 inperspective asked Aug 8, 2015 at 5:27 inperspectiveinperspective 1,9041 gold badge20 silver badges22 bronze badges1 Answer
Reset to default 11This is expected behavior. Lodash will only perform this optimization on arrays with 200 or more items. Increase the range to 200 in the first line to see this working.
本文标签: javascriptLazy Evaluation Not Working In LodashStack Overflow
版权声明:本文标题:javascript - Lazy Evaluation Not Working In Lodash - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742240647a2438811.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论