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.

Can flyd streams be made lazy ?

See original GitHub issue

when you have nodejs style API, you have this:

var fs = requie('fs');

var flyd = requie('flyd');

var read_hello = flyd.stream();

fs.readfile('./hello.txt',read_hello); // <- this runs immediately :(

read_hello.map(function(){/...../});

Is there some magic I can do to turn the stream upside down to make it lazy ?

var fs = requie('fs');

var flyd = requie('flyd');

var read_hello = flyd.stream();

read_hello = flyd.lazy(function(stream){

  fs.readfile('./hello.txt',stream);

});

read_hello.map(function(){/...../}).run(); // <- runs here !

Cheers !

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nordfjordcommented, Jul 29, 2020

don’t worry, I understand what you’re trying to accomplish.

I’m curious about your use case though, what use case do you have that requires lazy streams?

1reaction
nordfjordcommented, Jul 28, 2020

Hey @sourcevault ! Glad you found a solution!

I think you might be able to make a generic nodeback -> Stream function.

function fromNode(fn) {
  return (...args)=> {
    const s = stream()
    fn(...args, (err, data)=> s(data))
    return s
  }
}

Then you could use that as:

const readFile = fromNode(fs.readFile)

readFile('file1.txt')
  .map(x => x.toString())
  .map(console.log)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Stream and lazy evaluation - java - Stack Overflow
Streams are lazy because intermediate operations are not evaluated unless terminal operation is invoked. Each intermediate operation creates a ...
Read more >
Java 8 Streams - Lazy evaluation - LogicBig
Streams are lazy because intermediate operations are not evaluated until terminal ... The pipeline accumulates these newly created streams.
Read more >
Java 8 Streams Lazy evaluation - LinkedIn
Streams are lazy because intermediate operations are not evaluated until terminal operation is invoked. Each intermediate operation creates ...
Read more >
Why Java 8 Streams Are Lazy Explain ? | InterviewDOT
Click here - https://www.youtube.com/channel/UCd0U_xlQxdZynq09knDszXA?sub_confirmation=1 to get notifications.Why Java 8 Streams Are Lazy ...
Read more >
Is Vaush getting lazy or giving up? : r/VaushV - Reddit
It's starting to show with his video/stream view-count as well. He is still my favourite streamer but I was wondering if you guys...
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