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

kotlin.reflect.jvm.internal.impl.utils.formattingHelpers.kt Maven / Gradle / Ivy

There is a newer version: 2.1.20-RC3
Show newest version
/*
 * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package kotlin.reflect.jvm.internal.impl.utils

inline fun  Collection.joinToEnglishString(conjunction: String, format: (E) -> String): String =
    when {
        isEmpty() -> ""
        size == 1 -> format(first())
        else -> buildString {
            val list = [email protected]()

            for (it in 0 until list.size - 1) {
                append(format(list[it]))
                append(", ")
            }

            append("$conjunction ${format(list.last())}")
        }
    }

inline fun  Collection.joinToEnglishOrString(format: (E) -> String = { it.toString() }): String =
    joinToEnglishString("or", format)

inline fun  Collection.joinToEnglishAndString(format: (E) -> String = { it.toString() }): String =
    joinToEnglishString("and", format)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy