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

commonMain.dev.inmo.micro_utils.common.PadExtensions.kt Maven / Gradle / Ivy

The newest version!
package dev.inmo.micro_utils.common

inline fun  Sequence.padWith(size: Int, inserter: (Sequence) -> Sequence): Sequence {
    var result = this
    while (result.count() < size) {
        result = inserter(result)
    }
    return result
}

inline fun  Sequence.padEnd(size: Int, padBlock: (Int) -> T): Sequence = padWith(size) { it + padBlock(it.count()) }

inline fun  Sequence.padEnd(size: Int, o: T) = padEnd(size) { o }

inline fun  List.padWith(size: Int, inserter: (List) -> List): List {
    var result = this
    while (result.size < size) {
        result = inserter(result)
    }
    return result
}
inline fun  List.padEnd(size: Int, padBlock: (Int) -> T): List = asSequence().padEnd(size, padBlock).toList()

inline fun  List.padEnd(size: Int, o: T): List = asSequence().padEnd(size, o).toList()

inline fun  Sequence.padStart(size: Int, padBlock: (Int) -> T): Sequence = padWith(size) { sequenceOf(padBlock(it.count())) + it }

inline fun  Sequence.padStart(size: Int, o: T) = padStart(size) { o }

inline fun  List.padStart(size: Int, padBlock: (Int) -> T): List = asSequence().padStart(size, padBlock).toList()

inline fun  List.padStart(size: Int, o: T): List = asSequence().padStart(size, o).toList()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy