使用lodash的显式链接不应用快捷方式融合 [英] Explicit chaining with lodash doesn't apply shortcut fusion

查看:76
本文介绍了使用lodash的显式链接不应用快捷方式融合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用lodash时,我发现当我使用隐式链接时,它应用了快捷方式融合.

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

如您所见,传递给map的函数被调用了三次,而不是调用一次,这表明lodash没有应用快捷方式融合.

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. 这是预期的行为吗?
  2. 如果可以的话,他们在文件中的何处解释这种行为?
  3. 是否可以通过显式链接应用快捷方式融合?

我在node.js v8.10.0上使用lodash 4.17.5.

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

推荐答案

我发现了一张票证在其GitHub项目上了解此问题.

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

这是出乎意料的,但现在是这样.

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

这篇关于使用lodash的显式链接不应用快捷方式融合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆