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

com.river.connector.github.internal.Ext.kt Maven / Gradle / Ivy

There is a newer version: 1.0.0-alpha18
Show newest version
package com.river.connector.github.internal

import com.river.connector.github.model.query.PageableQuery
import com.river.core.*
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.flow.withIndex

internal val regex = "([a-z])([A-Z]+)".toRegex()
internal const val replacement = "$1_$2"

internal fun String.snakeCase(): String =
    this.replace(regex, replacement).lowercase()

internal fun  paginatedFlowApi(
    filter: Q.() -> Unit,
    concurrency: Int,
    f: suspend (Q.() -> Unit) -> List
) = indefinitelyRepeat(filter)
    .withIndex()
    .map { (index, filter) -> (index + 1) to filter  }
    .mapAsync(concurrency) { (page, filter) ->
        f {
            filter()
            this.page = page
        }
    }
    .takeWhile { it.isNotEmpty() }
    .flattenIterable()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy