getify / fasy

FP iterators that are both eager and asynchronous

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[docs] how about for..of loop for sequential processing?

ducin opened this issue · comments

Hi @getify,

Wanted to comment on a part of the readme below:

Unfortunately, aside from being more verbose, this "fix" is fairly limited. It really only works for map(..) and not for something like filter(..). Also, since it assumes concurrency, there's no way to do the iterations serially (for any of various reasons).

although assumes concurrency is true for async functions inside of Promise.all, you still have for..of loop available which would perfectly suit iterating over users (let it be array or any other iterable) that, given you await inside the loop, make it native sequential processing.

So I'm not sure if there's no way to do the iterations serially. Sure it fits map only - doesn't fit filter, reduce - but it's worth mentioning. IMHO it's the easiest approach for sequential processing within async functions, if you just map items sequentially.

Anyway, good work, as always! :)

I totally agree that for..of loops allow serial processing. In general, this is actually my stylistic preference. However, this library exists to serve the mindset that you either want:

  1. to avoid all imperative loops and use only FP iterators; --OR--
  2. you want to do filter/etc serially

I think the objection you have is the "...there's no way to do the iterations..." part. To clarify, I could either change that to "...there's no FP-style way to do the iterations..." or "...there's no way to do the FP-style iterations..." Do either of those address the concern you have?

Yep, the (FP) style is the key here. Both are ok :)

PS as for the point 2 you mentioned:

you want to do filter/etc serially

what do you mean here? I can filter/etc using for..of + manually create/mutate arrays (imperative style). I can't do that the FP way - but it falls down to point 1. Or maybe there's something I'm missing?

Sorry I think I meant concurrently

addressed in fe557d5