commonMain.dev.inmo.micro_utils.common.PadExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro_utils.common-jvm Show documentation
Show all versions of micro_utils.common-jvm Show documentation
It is set of projects with micro tools for avoiding of routines coding
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