ocaml-gitlab icon indicating copy to clipboard operation
ocaml-gitlab copied to clipboard

RFC: Stream: add total

Open arvidj opened this issue 2 years ago • 0 comments

This code shouldn't be merged. However, posting it to get some comments. For a given use case, I needed to know the total number of items for a given paginated stream, without requesting all items in the stream (being very long). The ugly thing about the hack to this end in this PR is that you have to get the first element of the stream (by calling Stream.next) before Stream.total becomes available.

Nicer solutions could be:

  • Having Stream.total force the stream
  • Changing the type of Stream.t so that the user has to provide a function that returns the total number of elements in the stream. When creating a Stream.t from GitLab API requests, this function can do e.g. an HTTP HEAD on the API endpoint to get the total number.

Any ideas?

arvidj avatar Oct 10 '23 12:10 arvidj