Lazy cursor walker behind every *_stream helper.
Slack cursor pagination: pass cursor, read response_metadata.next_cursor; an
empty or missing next_cursor ends the walk. Pages are fetched only as the consumer
pulls. A failed page fetch raises the %Noizu.Slack.Error{} (a stream cannot
return an error tuple) — rescue at the enumeration site if needed.
Noizu.Slack.Pagination.stream(
fn cursor -> Noizu.Slack.Request.get(client, "conversations.list", %{cursor: cursor}) end,
results_key: "channels"
)
|> Enum.take(500)
Summary
Functions
Returns the page's response_metadata.next_cursor, or nil when exhausted.
Builds a stream of items. fetch receives nil for the first page and the
previous page's next_cursor afterwards.
Puts (or drops) cursor in a params map.
Types
@type fetch() :: (String.t() | nil -> {:ok, map()} | {:error, Noizu.Slack.Error.t()})
Functions
Returns the page's response_metadata.next_cursor, or nil when exhausted.
@spec stream(fetch(), keyword()) :: Enumerable.t()
Builds a stream of items. fetch receives nil for the first page and the
previous page's next_cursor afterwards.
Options: :results_key (required) — the list key in each page ("channels",
"members", "messages", …).
Puts (or drops) cursor in a params map.