diff --git a/CHANGELOG.md b/CHANGELOG.md index f9c6e12e271..2860bd4a4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.5.23 + +* `Versions`: + * `Exposed`: `0.33.1` -> `0.34.1` +* `Common`: + * New extensions `Iterable#joinTo` and `Array#joinTo` + ## 0.5.22 * `Versions` diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/JoinTo.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/JoinTo.kt new file mode 100644 index 00000000000..e6919928160 --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/JoinTo.kt @@ -0,0 +1,59 @@ +package dev.inmo.micro_utils.common + +inline fun Iterable.joinTo( + crossinline separatorFun: (I) -> R?, + prefix: R? = null, + postfix: R? = null, + crossinline transform: (I) -> R? +): List { + val result = mutableListOf() + val iterator = iterator() + + prefix ?.let(result::add) + + while (iterator.hasNext()) { + val element = iterator.next() + result.add(transform(element) ?: continue) + + if (iterator.hasNext()) { + result.add(separatorFun(element) ?: continue) + } + } + + postfix ?.let(result::add) + + return result +} + +inline fun Iterable.joinTo( + separator: R? = null, + prefix: R? = null, + postfix: R? = null, + crossinline transform: (I) -> R? +): List = joinTo({ separator }, prefix, postfix, transform) + +inline fun Iterable.joinTo( + crossinline separatorFun: (I) -> I?, + prefix: I? = null, + postfix: I? = null +): List = joinTo(separatorFun, prefix, postfix) { it } + +inline fun Iterable.joinTo( + separator: I? = null, + prefix: I? = null, + postfix: I? = null +): List = joinTo({ separator }, prefix, postfix) + +inline fun Array.joinTo( + crossinline separatorFun: (I) -> R?, + prefix: R? = null, + postfix: R? = null, + crossinline transform: (I) -> R? +): Array = asIterable().joinTo(separatorFun, prefix, postfix, transform).toTypedArray() + +inline fun Array.joinTo( + separator: R? = null, + prefix: R? = null, + postfix: R? = null, + crossinline transform: (I) -> R? +): Array = asIterable().joinTo(separator, prefix, postfix, transform).toTypedArray() diff --git a/gradle.properties b/gradle.properties index 6ab369bee77..09c465ae2d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2g kotlin_version=1.5.30 kotlin_coroutines_version=1.5.1 kotlin_serialisation_core_version=1.2.2 -kotlin_exposed_version=0.33.1 +kotlin_exposed_version=0.34.1 ktor_version=1.6.3 @@ -45,5 +45,5 @@ dokka_version=1.5.0 # Project data group=dev.inmo -version=0.5.22 -android_code_version=63 +version=0.5.23 +android_code_version=64