Search code examples
javascriptnode.jslodash

Explicit chaining with lodash doesn't apply shortcut fusion


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.


Solution

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

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