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

ru.testit.kotlin.client.infrastructure.ApiAbstractions.kt Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package ru.testit.kotlin.client.infrastructure

typealias MultiValueMap = MutableMap>

fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
    "csv" -> ","
    "tsv" -> "\t"
    "pipe" -> "|"
    "space" -> " "
    else -> ""
}

val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }

fun  toMultiValue(items: Array, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
        = toMultiValue(items.asIterable(), collectionFormat, map)

fun  toMultiValue(items: Iterable, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List {
    return when(collectionFormat) {
        "multi" -> items.map(map)
        else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy