Package-level declarations

Types

Link copied to clipboard
class PaginatedIterable<T>(pageSize: Int, countGetter: () -> Long, paginationResultGetter: Pagination.() -> PaginationResult<T>) : Iterable<T>

An iterable that lazily fetches items from a paginated data source. It creates a PaginatedIterator that automatically fetches pages as needed.

Link copied to clipboard
class PaginatedIterator<T>(pageSize: Int, countGetter: () -> Long, paginationResultGetter: Pagination.() -> PaginationResult<T>) : Iterator<T>

An iterator that lazily fetches items from a paginated data source. It automatically fetches the next page when the current page is exhausted.

Functions

Link copied to clipboard
inline fun <T> doAllWithCurrentPaging(initialPagination: Pagination = FirstPagePagination(), block: (Pagination) -> PaginationResult<T>)

Executes block for each page in a paginated sequence, automatically moving to the next page until an empty page or the last page is reached. Uses current page pagination logic.

Link copied to clipboard
inline fun <T> doForAll(initialPagination: Pagination = FirstPagePagination(), paginationMapper: (PaginationResult<T>) -> Pagination?, block: (Pagination) -> PaginationResult<T>)

Executes block for each page in a paginated sequence. The paginationMapper determines the next pagination to use based on the current result. Stops when paginationMapper returns null.

Link copied to clipboard
inline fun <T> doForAllWithCurrentPaging(initialPagination: Pagination = FirstPagePagination(), block: (Pagination) -> PaginationResult<T>)

Alias for doAllWithCurrentPaging. Executes block for each page in a paginated sequence.

Link copied to clipboard
inline fun <T> doForAllWithNextPaging(initialPagination: Pagination = FirstPagePagination(), block: (Pagination) -> PaginationResult<T>)

Executes block for each page in a paginated sequence, automatically moving to the next page until an empty page or the last page is reached.

Link copied to clipboard
inline fun <T> getAll(initialPagination: Pagination = FirstPagePagination(), paginationMapper: (PaginationResult<T>) -> Pagination?, block: (Pagination) -> PaginationResult<T>): List<T>

Retrieves all items from a paginated source by repeatedly calling block with different pagination parameters. The paginationMapper determines the next pagination to use based on the current result.

Link copied to clipboard
inline fun <T, R> R.getAllBy(initialPagination: Pagination = FirstPagePagination(), paginationMapper: R.(PaginationResult<T>) -> Pagination?, block: R.(Pagination) -> PaginationResult<T>): List<T>

Retrieves all items from a paginated source using a receiver context. This is useful when the pagination logic depends on the receiver object's state.

Link copied to clipboard
inline fun <T, R> R.getAllByWithCurrentPaging(initialPagination: Pagination = FirstPagePagination(), block: R.(Pagination) -> PaginationResult<T>): List<T>

Retrieves all items from a paginated source using a receiver context, automatically moving to the next page until an empty page or the last page is reached. Uses current page pagination logic.

Link copied to clipboard
inline fun <T, R> R.getAllByWithNextPaging(initialPagination: Pagination = FirstPagePagination(), block: R.(Pagination) -> PaginationResult<T>): List<T>

Retrieves all items from a paginated source using a receiver context, automatically moving to the next page until an empty page or the last page is reached.

Link copied to clipboard
inline fun <T> getAllWithCurrentPaging(initialPagination: Pagination = FirstPagePagination(), block: (Pagination) -> PaginationResult<T>): List<T>

Retrieves all items from a paginated source, automatically moving to the next page until an empty page or the last page is reached. Uses current page pagination logic.

Link copied to clipboard
inline fun <T> getAllWithNextPaging(initialPagination: Pagination = FirstPagePagination(), block: (Pagination) -> PaginationResult<T>): List<T>

Retrieves all items from a paginated source, automatically moving to the next page until an empty page or the last page is reached.

Link copied to clipboard
inline fun <T> makeIterable(noinline countGetter: () -> Long, pageSize: Int = defaultPaginationPageSize, noinline paginationResultGetter: Pagination.() -> PaginationResult<T>): Iterable<T>

Creates an Iterable that lazily fetches items from a paginated data source. This is useful for iterating over large datasets without loading all items into memory at once.

Link copied to clipboard
inline fun <T> Array<T>.optionallyReverse(reverse: Boolean): Array<T>

Optionally reverses this Array based on the reverse parameter.

Optionally reverses this Iterable based on the reverse parameter. Delegates to specialized implementations for List and Set for better performance.

fun <T> List<T>.optionallyReverse(reverse: Boolean): List<T>

Optionally reverses this List based on the reverse parameter.

fun <T> Set<T>.optionallyReverse(reverse: Boolean): Set<T>

Optionally reverses this Set based on the reverse parameter. Note that the resulting set may have a different iteration order than the original.

fun Pagination.optionallyReverse(objectsCount: Int, reverse: Boolean): Pagination
fun Pagination.optionallyReverse(objectsCount: Long, reverse: Boolean): Pagination
Link copied to clipboard

Paginates this Iterable according to the given Pagination parameters. Returns a PaginationResult containing the items within the specified page range.

Paginates this List according to the given Pagination parameters. Returns a PaginationResult containing the items within the specified page range. More efficient than the Iterable version as it uses direct indexing.

Paginates this Set according to the given Pagination parameters. Returns a PaginationResult containing the items within the specified page range.

fun <T> List<T>.paginate(with: Pagination, reversed: Boolean): PaginationResult<T>

Paginates this List according to the given Pagination parameters, optionally in reverse order.

fun <T> Set<T>.paginate(with: Pagination, reversed: Boolean): PaginationResult<T>

Paginates this Set according to the given Pagination parameters, optionally in reverse order.

Link copied to clipboard

Shortcut for reverse

Example: