All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dev.inmo.micro_utils.pagination.utils.GetAll.kt Maven / Gradle / Ivy

The newest version!
package dev.inmo.micro_utils.pagination.utils

import dev.inmo.micro_utils.pagination.*

inline fun  getAll(
    initialPagination: Pagination = FirstPagePagination(),
    paginationMapper: (PaginationResult) -> Pagination?,
    block: (Pagination) -> PaginationResult
): List {
    val results = mutableListOf()
    doForAll(initialPagination, paginationMapper) {
        block(it).also {
            results.addAll(it.results)
        }
    }
    return results.toList()
}

inline fun  R.getAllBy(
    initialPagination: Pagination = FirstPagePagination(),
    paginationMapper: R.(PaginationResult) -> Pagination?,
    block: R.(Pagination) -> PaginationResult
): List = getAll(
    initialPagination,
    { paginationMapper(it) },
    { block(it) }
)

inline fun  getAllWithNextPaging(
    initialPagination: Pagination = FirstPagePagination(),
    block: (Pagination) -> PaginationResult
): List = getAll(
    initialPagination,
    { it.nextPageIfNotEmptyOrLastPage() },
    block
)

inline fun  R.getAllByWithNextPaging(
    initialPagination: Pagination = FirstPagePagination(),
    block: R.(Pagination) -> PaginationResult
): List = getAllWithNextPaging(
    initialPagination,
    { block(it) }
)

inline fun  getAllWithCurrentPaging(
    initialPagination: Pagination = FirstPagePagination(),
    block: (Pagination) -> PaginationResult
): List = getAll(
    initialPagination,
    { it.thisPageIfNotEmptyOrLastPage() },
    block
)

inline fun  R.getAllByWithCurrentPaging(
    initialPagination: Pagination = FirstPagePagination(),
    block: R.(Pagination) -> PaginationResult
): List = getAllWithCurrentPaging(
    initialPagination
) { block(it) }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy