ocaml-gitlab
ocaml-gitlab copied to clipboard
RFC: Stream: add total
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.totalforce the stream - Changing the type of
Stream.tso that the user has to provide a function that returns the total number of elements in the stream. When creating aStream.tfrom GitLab API requests, this function can do e.g. an HTTP HEAD on the API endpoint to get the total number.
Any ideas?