generate docs for a lot of API (test try)

This commit is contained in:
2026-02-24 18:18:10 +06:00
parent 3df90b1993
commit 4f270d9047
81 changed files with 2519 additions and 6 deletions

View File

@@ -2,6 +2,16 @@ package dev.inmo.micro_utils.pagination.utils
import dev.inmo.micro_utils.pagination.*
/**
* 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.
*
* @param T The type of items in each page
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param paginationMapper Function that determines the next pagination based on the current result. Return null to stop
* @param block Function that processes each page and returns a [PaginationResult]
*/
inline fun <T> doForAll(
initialPagination: Pagination = FirstPagePagination(),
paginationMapper: (PaginationResult<T>) -> Pagination?,
@@ -12,6 +22,14 @@ inline fun <T> doForAll(
}
}
/**
* 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.
*
* @param T The type of items in each page
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param block Function that processes each page and returns a [PaginationResult]
*/
inline fun <T> doForAllWithNextPaging(
initialPagination: Pagination = FirstPagePagination(),
block: (Pagination) -> PaginationResult<T>
@@ -23,6 +41,14 @@ inline fun <T> doForAllWithNextPaging(
)
}
/**
* 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.
*
* @param T The type of items in each page
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param block Function that processes each page and returns a [PaginationResult]
*/
inline fun <T> doAllWithCurrentPaging(
initialPagination: Pagination = FirstPagePagination(),
block: (Pagination) -> PaginationResult<T>
@@ -34,6 +60,13 @@ inline fun <T> doAllWithCurrentPaging(
)
}
/**
* Alias for [doAllWithCurrentPaging]. Executes [block] for each page in a paginated sequence.
*
* @param T The type of items in each page
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param block Function that processes each page and returns a [PaginationResult]
*/
inline fun <T> doForAllWithCurrentPaging(
initialPagination: Pagination = FirstPagePagination(),
block: (Pagination) -> PaginationResult<T>

View File

@@ -2,6 +2,16 @@ package dev.inmo.micro_utils.pagination.utils
import dev.inmo.micro_utils.pagination.*
/**
* 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.
*
* @param T The type of items being retrieved
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param paginationMapper Function that determines the next pagination based on the current result. Return null to stop
* @param block Function that retrieves a page of results for the given pagination
* @return A list containing all retrieved items from all pages
*/
inline fun <T> getAll(
initialPagination: Pagination = FirstPagePagination(),
paginationMapper: (PaginationResult<T>) -> Pagination?,
@@ -16,6 +26,17 @@ inline fun <T> getAll(
return results.toList()
}
/**
* 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.
*
* @param T The type of items being retrieved
* @param R The receiver type
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param paginationMapper Function that determines the next pagination based on the current result
* @param block Function that retrieves a page of results for the given pagination using the receiver context
* @return A list containing all retrieved items from all pages
*/
inline fun <T, R> R.getAllBy(
initialPagination: Pagination = FirstPagePagination(),
paginationMapper: R.(PaginationResult<T>) -> Pagination?,
@@ -26,6 +47,15 @@ inline fun <T, R> R.getAllBy(
{ block(it) }
)
/**
* Retrieves all items from a paginated source, automatically moving to the next page
* until an empty page or the last page is reached.
*
* @param T The type of items being retrieved
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param block Function that retrieves a page of results for the given pagination
* @return A list containing all retrieved items from all pages
*/
inline fun <T> getAllWithNextPaging(
initialPagination: Pagination = FirstPagePagination(),
block: (Pagination) -> PaginationResult<T>
@@ -35,6 +65,16 @@ inline fun <T> getAllWithNextPaging(
block
)
/**
* 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.
*
* @param T The type of items being retrieved
* @param R The receiver type
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param block Function that retrieves a page of results for the given pagination using the receiver context
* @return A list containing all retrieved items from all pages
*/
inline fun <T, R> R.getAllByWithNextPaging(
initialPagination: Pagination = FirstPagePagination(),
block: R.(Pagination) -> PaginationResult<T>
@@ -43,6 +83,15 @@ inline fun <T, R> R.getAllByWithNextPaging(
{ block(it) }
)
/**
* 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.
*
* @param T The type of items being retrieved
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param block Function that retrieves a page of results for the given pagination
* @return A list containing all retrieved items from all pages
*/
inline fun <T> getAllWithCurrentPaging(
initialPagination: Pagination = FirstPagePagination(),
block: (Pagination) -> PaginationResult<T>
@@ -52,6 +101,17 @@ inline fun <T> getAllWithCurrentPaging(
block
)
/**
* 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.
*
* @param T The type of items being retrieved
* @param R The receiver type
* @param initialPagination The pagination to start with. Defaults to [FirstPagePagination]
* @param block Function that retrieves a page of results for the given pagination using the receiver context
* @return A list containing all retrieved items from all pages
*/
inline fun <T, R> R.getAllByWithCurrentPaging(
initialPagination: Pagination = FirstPagePagination(),
block: R.(Pagination) -> PaginationResult<T>

View File

@@ -1,5 +1,13 @@
package dev.inmo.micro_utils.pagination.utils
/**
* Optionally reverses this [Iterable] based on the [reverse] parameter.
* Delegates to specialized implementations for [List] and [Set] for better performance.
*
* @param T The type of items in the iterable
* @param reverse If true, reverses the iterable; otherwise returns it unchanged
* @return The iterable, optionally reversed
*/
fun <T> Iterable<T>.optionallyReverse(reverse: Boolean): Iterable<T> = when (this) {
is List<T> -> optionallyReverse(reverse)
is Set<T> -> optionallyReverse(reverse)
@@ -9,17 +17,41 @@ fun <T> Iterable<T>.optionallyReverse(reverse: Boolean): Iterable<T> = when (thi
this
}
}
/**
* Optionally reverses this [List] based on the [reverse] parameter.
*
* @param T The type of items in the list
* @param reverse If true, reverses the list; otherwise returns it unchanged
* @return The list, optionally reversed
*/
fun <T> List<T>.optionallyReverse(reverse: Boolean): List<T> = if (reverse) {
reversed()
} else {
this
}
/**
* Optionally reverses this [Set] based on the [reverse] parameter.
* Note that the resulting set may have a different iteration order than the original.
*
* @param T The type of items in the set
* @param reverse If true, reverses the set; otherwise returns it unchanged
* @return The set, optionally reversed
*/
fun <T> Set<T>.optionallyReverse(reverse: Boolean): Set<T> = if (reverse) {
reversed().toSet()
} else {
this
}
/**
* Optionally reverses this [Array] based on the [reverse] parameter.
*
* @param T The type of items in the array
* @param reverse If true, creates a reversed copy of the array; otherwise returns it unchanged
* @return The array, optionally reversed
*/
inline fun <reified T> Array<T>.optionallyReverse(reverse: Boolean) = if (reverse) {
Array(size) {
get(lastIndex - it)

View File

@@ -2,6 +2,14 @@ package dev.inmo.micro_utils.pagination.utils
import dev.inmo.micro_utils.pagination.*
/**
* Paginates this [Iterable] according to the given [Pagination] parameters.
* Returns a [PaginationResult] containing the items within the specified page range.
*
* @param T The type of items in the iterable
* @param with The pagination parameters specifying which page to retrieve
* @return A [PaginationResult] containing the items from the requested page
*/
fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
var i = 0
val result = mutableListOf<T>()
@@ -20,6 +28,15 @@ fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
return result.createPaginationResult(with, i.toLong())
}
/**
* 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.
*
* @param T The type of items in the list
* @param with The pagination parameters specifying which page to retrieve
* @return A [PaginationResult] containing the items from the requested page
*/
fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
if (with.firstIndex >= size || with.lastIndex < 0) {
return emptyPaginationResult(with, size.toLong())
@@ -30,6 +47,14 @@ fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
)
}
/**
* Paginates this [List] according to the given [Pagination] parameters, optionally in reverse order.
*
* @param T The type of items in the list
* @param with The pagination parameters specifying which page to retrieve
* @param reversed If true, the list will be paginated in reverse order
* @return A [PaginationResult] containing the items from the requested page, optionally reversed
*/
fun <T> List<T>.paginate(with: Pagination, reversed: Boolean): PaginationResult<T> {
return if (reversed) {
val actualPagination = with.optionallyReverse(
@@ -42,6 +67,14 @@ fun <T> List<T>.paginate(with: Pagination, reversed: Boolean): PaginationResult<
}
}
/**
* Paginates this [Set] according to the given [Pagination] parameters.
* Returns a [PaginationResult] containing the items within the specified page range.
*
* @param T The type of items in the set
* @param with The pagination parameters specifying which page to retrieve
* @return A [PaginationResult] containing the items from the requested page
*/
fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
return this.drop(with.firstIndex).take(with.size).createPaginationResult(
with,
@@ -49,6 +82,14 @@ fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
)
}
/**
* Paginates this [Set] according to the given [Pagination] parameters, optionally in reverse order.
*
* @param T The type of items in the set
* @param with The pagination parameters specifying which page to retrieve
* @param reversed If true, the set will be paginated in reverse order
* @return A [PaginationResult] containing the items from the requested page, optionally reversed
*/
fun <T> Set<T>.paginate(with: Pagination, reversed: Boolean): PaginationResult<T> {
val actualPagination = with.optionallyReverse(
size,

View File

@@ -2,6 +2,15 @@ package dev.inmo.micro_utils.pagination.utils
import dev.inmo.micro_utils.pagination.*
/**
* An iterator that lazily fetches items from a paginated data source.
* It automatically fetches the next page when the current page is exhausted.
*
* @param T The type of items being iterated
* @param pageSize The size of each page to fetch
* @param countGetter A function that returns the total count of available items
* @param paginationResultGetter A function that fetches a page of results for a given pagination
*/
class PaginatedIterator<T>(
pageSize: Int,
private val countGetter: () -> Long,
@@ -22,6 +31,15 @@ class PaginatedIterator<T>(
}
}
/**
* An iterable that lazily fetches items from a paginated data source.
* It creates a [PaginatedIterator] that automatically fetches pages as needed.
*
* @param T The type of items being iterated
* @param pageSize The size of each page to fetch
* @param countGetter A function that returns the total count of available items
* @param paginationResultGetter A function that fetches a page of results for a given pagination
*/
class PaginatedIterable<T>(
private val pageSize: Int,
private val countGetter: () -> Long,
@@ -31,7 +49,14 @@ class PaginatedIterable<T>(
}
/**
* Will make iterable using incoming [countGetter] and [paginationResultGetter]
* 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.
*
* @param T The type of items being iterated
* @param countGetter A function that returns the total count of available items
* @param pageSize The size of each page to fetch. Defaults to [defaultPaginationPageSize]
* @param paginationResultGetter A function that fetches a page of results for a given pagination
* @return An [Iterable] that can be used in for-loops or other iterable contexts
*/
@Suppress("NOTHING_TO_INLINE")
inline fun <T> makeIterable(