ngs-lang / ngs

Next Generation Shell (NGS)
https://ngs-lang.org/
GNU General Public License v3.0
1.48k stars 41 forks source link

Paginator facility #351

Open ilyash opened 4 years ago

ilyash commented 4 years ago

Paginator facility (or method). The intended use is to support APIs that require pagination.

Usage might look like like the following:

collector paginator(F(token) {
  # ignoring the fact that  --starting-token is not needed on first run, when token is null:
  # for removing --starting-token when token is null there should be new syntax
  users = ``aws cognito-idp list-users-in-group ... --starting-token $token``
  users.each(collect)
  users.get('NextToken')
})
ilyash commented 3 years ago

Thinking. Maybe like this (not tested):

doc start - fetch first page
doc step - fetch second and on page, based on output from body()
doc body - process the page and extract "next token" to feed into step()
F paginate(start:Fun, step:Fun, body:Fun) {
    cont = body(start())
    while cont is not Null {
        cont = body(step(cont))
    }
}
ilyash-b commented 1 year ago

Also to do: Iter for pagination-based-fetched items