From 54cc353bcc7a4108280e2f892cf1ab08fd0e1d3d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Oct 2024 15:26:02 +0600 Subject: [PATCH 1/2] start 0.22.8 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9581a6a2102..032047c5da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.22.8 + ## 0.22.7 * `Versions`: diff --git a/gradle.properties b/gradle.properties index aaa620af696..b3d107e2b47 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 From 6245b36bdbec7dcd89c2c117a724890c11ebee65 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Oct 2024 15:30:10 +0600 Subject: [PATCH 2/2] add pads and breakAsPairs extensions --- CHANGELOG.md | 4 +++ .../inmo/micro_utils/common/BreakAsPairs.kt | 13 ++++++++ .../inmo/micro_utils/common/PadExtensions.kt | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 common/src/commonMain/kotlin/dev/inmo/micro_utils/common/BreakAsPairs.kt create mode 100644 common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PadExtensions.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 032047c5da6..045d5ef16d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 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`: diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/BreakAsPairs.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/BreakAsPairs.kt new file mode 100644 index 00000000000..d1e262e6188 --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/BreakAsPairs.kt @@ -0,0 +1,13 @@ +package dev.inmo.micro_utils.common + +fun List.breakAsPairs(): List> { + val result = mutableListOf>() + + for (i in 0 until size - 1) { + val first = get(i) + val second = get(i + 1) + result.add(first to second) + } + + return result +} diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PadExtensions.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PadExtensions.kt new file mode 100644 index 00000000000..2bc5621d2ae --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PadExtensions.kt @@ -0,0 +1,32 @@ +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()