mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-01 05:53:50 +00:00
commit
f09d92be32
@ -1,5 +1,11 @@
|
||||
# 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
|
||||
|
||||
* `Versions`:
|
||||
|
@ -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
|
||||
}
|
@ -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()
|
@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.22.7
|
||||
android_code_version=273
|
||||
version=0.22.8
|
||||
android_code_version=274
|
||||
|
Loading…
Reference in New Issue
Block a user