henrik / progress_bar

Command-line progress bars and spinners for Elixir.
MIT License
334 stars 20 forks source link

Enum plugable bar #19

Open kelvinst opened 7 years ago

kelvinst commented 7 years ago

It would be awesome to have an easy way to plug this in a Enum/Stream/Flow pipeline. Since nowadays we have to do something like:

count = length(list)

list
|> Stream.with_index(1)
|> Stream.map(fn({item, idx}) ->
  ProgressBar.render(idx, count)
  item
end)
|> process_list

What I suggest is something like:

list
|> ProgressBar.from_enumerable(progress_bar_opts)
|> process_list

Together with progress_bar_opts, I guess it would be a good thing if we ask the count, since then the length can be calculated only once and for all.

I would be glad to open a PR, but maybe I will not be able to do it soon.

henrik commented 7 years ago

Great idea!