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

de.miraculixx.mcommons.extensions.CollectionExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
@file:Suppress("unused")

package de.miraculixx.mcommons.extensions

fun  List.toMap(default: V): Map {
    return buildMap {
        [email protected] { put(it, default) }
    }
}

/**
 * Returns the value after the given value in the list.
 * If the value is not found or the value is the last element, the first element is returned.
 */
fun  List.nextValue(value: T): T {
    val index = indexOf(value)
    return if (index == -1 || index == size - 1) first() else this[index + 1]
}

/**
 * Returns the value after the given value in the array.
 * If the value is not found or the value is the last element, the first element is returned.
 */
fun  Array.nextValue(value: T): T {
    val index = indexOf(value)
    return if (index == -1 || index == size - 1) first() else this[index + 1]
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy