Merge pull request #506 from InsanusMokrassar/0.22.8

0.22.8
This commit is contained in:
InsanusMokrassar 2024-10-24 16:32:18 +06:00 committed by GitHub
commit f09d92be32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 2 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 0.22.8
* `Common`:
* Add `List.breakAsPairs` extension
* Add `Sequence.padWith`/`Sequence.padStart`/`Sequence.padEnd` and `List.padWith`/`List.padStart`/`List.padEnd` extensions
## 0.22.7 ## 0.22.7
* `Versions`: * `Versions`:

View File

@ -0,0 +1,13 @@
package dev.inmo.micro_utils.common
fun <T> List<T>.breakAsPairs(): List<Pair<T, T>> {
val result = mutableListOf<Pair<T, T>>()
for (i in 0 until size - 1) {
val first = get(i)
val second = get(i + 1)
result.add(first to second)
}
return result
}

View File

@ -0,0 +1,32 @@
package dev.inmo.micro_utils.common
inline fun <T> Sequence<T>.padWith(size: Int, inserter: (Sequence<T>) -> Sequence<T>): Sequence<T> {
var result = this
while (result.count() < size) {
result = inserter(result)
}
return result
}
inline fun <T> Sequence<T>.padEnd(size: Int, padBlock: (Int) -> T): Sequence<T> = padWith(size) { it + padBlock(it.count()) }
inline fun <T> Sequence<T>.padEnd(size: Int, o: T) = padEnd(size) { o }
inline fun <T> List<T>.padWith(size: Int, inserter: (List<T>) -> List<T>): List<T> {
var result = this
while (result.size < size) {
result = inserter(result)
}
return result
}
inline fun <T> List<T>.padEnd(size: Int, padBlock: (Int) -> T): List<T> = asSequence().padEnd(size, padBlock).toList()
inline fun <T> List<T>.padEnd(size: Int, o: T): List<T> = asSequence().padEnd(size, o).toList()
inline fun <T> Sequence<T>.padStart(size: Int, padBlock: (Int) -> T): Sequence<T> = padWith(size) { sequenceOf(padBlock(it.count())) + it }
inline fun <T> Sequence<T>.padStart(size: Int, o: T) = padStart(size) { o }
inline fun <T> List<T>.padStart(size: Int, padBlock: (Int) -> T): List<T> = asSequence().padStart(size, padBlock).toList()
inline fun <T> List<T>.padStart(size: Int, o: T): List<T> = asSequence().padStart(size, o).toList()

View File

@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.22.7 version=0.22.8
android_code_version=273 android_code_version=274