getify / fasy

FP iterators that are both eager and asynchronous
MIT License
546 stars 18 forks source link

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

Closed ducin closed 6 years ago

ducin commented 6 years ago

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! :)

getify commented 6 years ago

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?

ducin commented 6 years ago

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?

getify commented 6 years ago

Sorry I think I meant concurrently

getify commented 6 years ago

addressed in fe557d5ccf41bdd5b5aa583678fac5427844be3f