caolan / caolan/highland

How to extract the result from reduce()

Open
#648 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

How do I reliably extract the final value from a reduce operation

eg
let numItems = -1
_([1, 2, 3]).reduce(0, (acc, value) => acc + 1).each(x => numItems = x)

This works for this simple example but for a more complex situation where the stream is a file that is split into lines its tricky.

At the nodejs command line it works but running in a test harness numItems is -1. I'm thinking that the stream hasn't finished reading the lines by the time I check the value.

How do I wait for it to finish before checking

Contributor guide

Open the contributing guide

Research direction

The issue names Highland's reduce operation, a file stream split into lines, and a test harness but no repository files or tests. Start by reproducing the command-line and test-harness cases, then trace when reduce completes relative to the assertion. Done would require a confirmed explanation and, if a project change is needed, a clearly specified regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.