# `Noizu.Slack.Pagination`
[🔗](https://github.com/noizu-labs-sdks/elixir-slack/blob/v0.1.0/lib/noizu/slack/pagination.ex#L1)

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)

# `fetch`

```elixir
@type fetch() :: (String.t() | nil -&gt; {:ok, map()} | {:error, Noizu.Slack.Error.t()})
```

# `next_cursor`

```elixir
@spec next_cursor(map()) :: String.t() | nil
```

Returns the page's `response_metadata.next_cursor`, or nil when exhausted.

# `stream`

```elixir
@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"`, …).

# `with_cursor`

```elixir
@spec with_cursor(map(), String.t() | nil) :: map()
```

Puts (or drops) `cursor` in a params map.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
