question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

".map" over console.log does not seem to show the stream

See original GitHub issue

Summary

The following code does not seem to show the stream:

from([1,2]).map(x=>console.log(x))

Expected result

Expected: 1 followed by 2 in the console

Actual Result

In the Node REPL:

Stream {
  source: Map { f: [Function], source: ArraySource { array: [Object] } } }

Versions

node@6.9.2

  • most.js: <version> most@1.3.0

Steps to reproduce

Node REPL

node
>most = require('most')
>most.from([1,2]).map(x=>console.log(x))
//=> Stream {
  source: Map { f: [Function], source: ArraySource { array: [Object] } } }

Code to reproduce

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Frikkicommented, Apr 29, 2017

@dmitriz As @TylorS explained, observe (f, stream) is really drain(tap(f, stream). f is your provided function that will perform a side effect on each item in the stream. Any return value of f is ignored. tab will then return a new stream with the same items as in the originally provided stream. The new stream is passed to drain, which returns a Promise. This Promise either fulfills when the stream ends without an error or is rejected if the stream ends with an error. Take note that the events of the stream are time-ordered.

Thus, if you have an “infinite” stream, e.g., a source that emits an event periodically, the provided function f will fire on every event, performing whatever side effect specified. Logically, the returned Promise will neither resolve nor reject (granted no errors occurred). After all, the stream is “infinite”. If the stream was finite (it ends), the code will then choose the path of either resolved or rejected Promise, if you so choose. As you see, the events are still consumed and passed to f.

You can easily map over the stream as in flyd, but you still need to consume the stream:

const stream = from([1, 2, 3])

const transformedStream = map(add2, stream)

function add2(value) { return value + 2 }

observe(console.log, transformedStream) // 3, 4, 5

Hope this helps (and that I didn’t provide any incorrect information in my explanation).

0reactions
briancavaliercommented, Aug 18, 2017

@dmitriz The original issue here seems to be resolved (observing the stream activates it), and it seems like @davidchase’s suggestion of looking at most-subject was helpful for your subsequent questions. So, I’m closing, but please re-open or create a new issue if there’s more we need to discuss.

Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why flatMap has no output when one stream has error?
Why flatMap has no output when one stream has error? ... I tried to write a program with highland.js to download several files,...
Read more >
Why map with console.log doesn't work - gists · GitHub
It works because map isn't being assigned to a variable, but I think the more proper way would be using forEach, as map...
Read more >
Console app not showing info and debug logs
I've tried running the Console app as root, via sudo from the command line and the same issue occurs; no debug or info...
Read more >
Node.js v19.3.0 Documentation
Commands in this document start with $ or > to replicate how they would appear in a user's terminal. Do not include the...
Read more >
View and save your browser console logs - Zapier Help
In rare instances, after you've contacted support we may need to see logs from your browser's console to see how it is interacting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found