Mercury.Pagination (mercury_client v1.0.0)

Copy Markdown View Source

Builds lazy, auto-paginating Streams over Mercury list endpoints.

Every resource module exposes a stream/2 built on top of this — you normally won't call stream/1 directly.

Summary

Functions

Returns a Stream of individual items across every page, given a page-fetching function of arity 1. The function receives the current cursor (nil for the first page) and must return {:ok, %Mercury.Page{}} or {:error, exception}.

Types

fetcher()

@type fetcher() :: (String.t() | nil ->
                {:ok, Mercury.Page.t()} | {:error, Exception.t()})

Functions

stream(fetch_fun)

@spec stream(fetch_fun :: fetcher()) :: Enumerable.t()

Returns a Stream of individual items across every page, given a page-fetching function of arity 1. The function receives the current cursor (nil for the first page) and must return {:ok, %Mercury.Page{}} or {:error, exception}.

The stream raises the underlying Mercury exception if a page request fails, consistent with how File.stream!/1 and similar raise on I/O errors mid-enumeration.