# paginate

> **paginate**\<`T`\>(`getPage`, `options?`): [`OutputType`](/reference/filoz/synapse-core/core/namespaces/paginate/type-aliases/outputtype/)\<`T`\>

Defined in: [packages/synapse-core/src/pagination.ts:108](https://github.com/FilOzone/synapse-sdk/blob/e6fb33f57d00c5c775ea37a127e65446e2eee635/packages/synapse-core/src/pagination.ts#L108)

Iterate over every item returned by a cursor-paginated action.

The generator passes each returned `nextCursor` back to `getPage`. Cursors
are opaque: callers must not calculate the next value themselves. A
repeated or non-advancing cursor is rejected to prevent an infinite loop.

## Type Parameters

| Type Parameter |
| ------ |
| `T` |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `getPage` | [`GetPage`](/reference/filoz/synapse-core/core/namespaces/paginate/type-aliases/getpage/)\<`T`\> | Function that fetches one page for the supplied cursor. |
| `options` | [`OptionsType`](/reference/filoz/synapse-core/core/namespaces/paginate/type-aliases/optionstype/) | Initial pagination options. |

## Returns

[`OutputType`](/reference/filoz/synapse-core/core/namespaces/paginate/type-aliases/outputtype/)\<`T`\>

An async generator that yields items from every page.

## Examples

**Stream items as pages are fetched**

```ts
import { paginate } from '@filoz/synapse-core'
import { getClientDataSetIds } from '@filoz/synapse-core/warm-storage'

for await (const dataSetId of paginate(({ cursor }) =>
  getClientDataSetIds(client, { address, cursor })
)) {
  console.log(dataSetId)
}
```

**Accumulate every item into an array**

```ts
import { paginate } from '@filoz/synapse-core'
import { getClientDataSetIds } from '@filoz/synapse-core/warm-storage'

const dataSetIds = await Array.fromAsync(
  paginate(({ cursor }) => getClientDataSetIds(client, { address, cursor }))
)
```