Just so I understand: Could this library be used for iterating large collections without blocking the main thread? Basically as a replacement for a worker with synchronous iteration?
Yes, but I'd add a caveat. It will be very efficient when the async operations are few, and slower. It will not be very efficient when the async operations are many and fast. That's because the await keyword itself blocks the main thread every time a function call is made. It has to because the `await` keyword is defined to return to the event loop and resume processing only during the next "tick" and after other que…
Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
31–40 of 51 posts
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#32Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#33Call me an idiot, but nowhere on the home page does it say it's for JavaScript. The code samples looked like JS, but I don't know every language, so I wasn't sure. It's not until I got into the docs and saw "npm" was a sure we were talking about JS...
it says "lfi is a lazy functional sync, async, and concurrent iteration library for JavaScript and TypeScript" when you click on the link though has it been added since?
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#34How does this compare to Effect, or Fluture? There have been so many attempts at improving these things in JS that it's hard to keep track.
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#35Split the array of elements to process. Set up a promise.all against a function that handles sync/async function calls against each chunk and accumulates an array of results. This isn't the end of the world for any of the practical use cases I can think of. The efficiency loss and memory consumption is miniscule even across hundreds of thousands of records. This is as concurrent as anything else - the event loop is still a mandatory part of the processing loop. You can even defer every 1000 records to the event loop. Javascript is syncronous so there is no concurrency without threading. I can't think of an IO or non-IO function that would create the issues described of not yielding. We used to have chunks of 1000000+ records that would freeze the event loop. We solved this with structured yields to the event loop to allow other processes to continue without dropping TCP packets etc.
If the results are objects, you're not even bloating memory too much. 800KB for 100,000 records seems fine for any practical use case.
I like the idea of an async generator to prevent over-pre-calculating the result set before it's needed but I couldn't justify pivoting to a set of new functions called pipe, map, etc that require a few too many logical leaps for your typical ECMAScript developers to understand.
What's the win here? It must be for some abuse of Javascript that should be ported to WASM. Or some other use-case that I've somehow not seen yet.
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#36I'm not sure I know the use case for all of this logical complexity. Is there a specific use-case you had in mind? Split the array of elements to process. Set up a promise.all against a function that handles sync/async function calls against each chunk and accumulates an array of results. This isn't the end of the world for any of the practical use cases I can think of. The efficiency loss and memory consumption is m…
> should be ported to WASM
valid.
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#37Another fp-ts
fp-ts seems more focused on "pure" functional programming in the style of languages like Haskell. It's much more opinionated on how you should write your code, including the data structures you should use. Plus, it's not really concerned with concurrency in the way that lfi is.
I think lfi is a lot less invasive/opinionated on how you write your code.
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#38Looks good (I understand all the word and even the whole sentence).
But what is it good for? ("What's in it for me?")
What are the use cases? How is it difference / how does it improve on / when should I use it instead of / ... lodash, ramda, functional.js, RxJs, etc.?
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#39I'm not sure I know the use case for all of this logical complexity. Is there a specific use-case you had in mind? Split the array of elements to process. Set up a promise.all against a function that handles sync/async function calls against each chunk and accumulates an array of results. This isn't the end of the world for any of the practical use cases I can think of. The efficiency loss and memory consumption is m…
It's a combination for writing the iteration code in a functional style, which some people like/prefer, while retaining certain performance characteristics that you'd get from writing more imperative code.
For example, the "naive" approach to functional programming + concurrency results in some unintentional bottlenecks (see the concurrent iteration example on the home page).
Re: Show HN: Lfi – a lazy functional sync, async, and concurrent iteration library
#40"lfi is a lazy functional sync, async, and concurrent iteration library for JavaScript and TypeScript" Looks good (I understand all the word and even the whole sentence). But what is it good for? ("What's in it for me?") What are the use cases? How is it difference / how does it improve on / when should I use it instead of / ... lodash, ramda, functional.js, RxJs, etc.?
I think the examples on the home page and in the "getting started" answer these questions to be honest. Do you feel it's unclear or something is missing?
> How is it difference / how does it improve on / when should I use it instead of / ... lodash, ramda, functional.js, RxJs, etc.?
I think some of that info is implicitly there in the docs, but I think this is good feedback. I should probably have a page comparing lfi vs other libraries.
To answer here though, for most of the libraries you mentioned, they don't provide support for _concurrent_ async iteration (and some of them don't support even sequential async iteration).
RxJS is the exception there I think. Although, I think lfi has a bit of a simpler API (that also matches the sync versions of the APIs) that's primarily designed for iteration rather than generalized observables. Plus, I don't _think_ RxJS has the same performance characteristics around tree-shakeability.