Zep.Pagination (Zep v1.0.0)

Copy Markdown View Source

Helper for turning a paginated list/2-style function into a lazy Stream that walks every page automatically.

Several list endpoints in the Zep API (thread.list_all, graph.list_all, user.list_ordered) share the same page_number / page_size / response_count / total_count envelope shape. Rather than duplicate page-walking logic per resource, each resource's stream/2 delegates here.

Example

Zep.Thread.stream(client, page_size: 100)
|> Stream.take(250)
|> Enum.to_list()

Summary

Functions

Builds a Stream over all pages, starting at page 1.

Types

fetch_page_fun()

@type fetch_page_fun() :: (page_number :: pos_integer(), page_size :: pos_integer() ->
                       {:ok, items :: list(),
                        total_count :: non_neg_integer() | nil}
                       | {:error, term()})

Functions

stream(page_size, fetch_page)

@spec stream(pos_integer(), fetch_page_fun()) :: Enumerable.t()

Builds a Stream over all pages, starting at page 1.

fetch_page is called with (page_number, page_size) and must return {:ok, items, total_count} or {:error, reason}. The stream halts after an empty page, after total_count items have been yielded (if known), or immediately on {:error, reason} (the error is emitted as the final stream element wrapped in {:error, reason} so consumers can detect it).