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

Lazy snowflake-cursor walker behind every `*_stream` helper.

Discord list endpoints page by `before`/`after` snowflake ids rather than opaque
cursors. `stream/2` calls `fetch.(cursor)` (`cursor` is `nil` for the first page,
then the next snowflake id), emits each item, and stops when a page is empty or
shorter than `:limit`.

A failed page fetch **raises** the `%Noizu.Discord.Error{}` (an enumerable cannot
return an error mid-stream); rescue at the enumeration site if desired.

## Options

  * `:direction` — `:after` (default; next cursor = largest id on the page) or
    `:before` (next cursor = smallest id).
  * `:limit` — page size requested; a shorter page ends the stream.
  * `:id_fun` — extracts the snowflake from an item (default `& &1["id"]`).
  * `:start` — initial cursor (default `nil`).

# `snowflake_compare`

```elixir
@spec snowflake_compare(String.t(), String.t()) :: :lt | :eq | :gt
```

Snowflake ordering helper: compares ids numerically.

# `stream`

```elixir
@spec stream(
  (String.t() | nil -&gt; {:ok, list()} | {:error, Noizu.Discord.Error.t()}),
  keyword()
) ::
  Enumerable.t()
```

---

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