Merge pull request #90 from InsanusMokrassar/0.5.23

0.5.23
This commit is contained in:
InsanusMokrassar 2021-09-02 14:35:31 +06:00 committed by GitHub
commit dc80ade2fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 3 deletions

View File

@ -1,5 +1,12 @@
# Changelog # Changelog
## 0.5.23
* `Versions`:
* `Exposed`: `0.33.1` -> `0.34.1`
* `Common`:
* New extensions `Iterable#joinTo` and `Array#joinTo`
## 0.5.22 ## 0.5.22
* `Versions` * `Versions`

View File

@ -0,0 +1,59 @@
package dev.inmo.micro_utils.common
inline fun <I, R> Iterable<I>.joinTo(
crossinline separatorFun: (I) -> R?,
prefix: R? = null,
postfix: R? = null,
crossinline transform: (I) -> R?
): List<R> {
val result = mutableListOf<R>()
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 <I, R> Iterable<I>.joinTo(
separator: R? = null,
prefix: R? = null,
postfix: R? = null,
crossinline transform: (I) -> R?
): List<R> = joinTo({ separator }, prefix, postfix, transform)
inline fun <I> Iterable<I>.joinTo(
crossinline separatorFun: (I) -> I?,
prefix: I? = null,
postfix: I? = null
): List<I> = joinTo<I, I>(separatorFun, prefix, postfix) { it }
inline fun <I> Iterable<I>.joinTo(
separator: I? = null,
prefix: I? = null,
postfix: I? = null
): List<I> = joinTo<I>({ separator }, prefix, postfix)
inline fun <I, reified R> Array<I>.joinTo(
crossinline separatorFun: (I) -> R?,
prefix: R? = null,
postfix: R? = null,
crossinline transform: (I) -> R?
): Array<R> = asIterable().joinTo(separatorFun, prefix, postfix, transform).toTypedArray()
inline fun <I, reified R> Array<I>.joinTo(
separator: R? = null,
prefix: R? = null,
postfix: R? = null,
crossinline transform: (I) -> R?
): Array<R> = asIterable().joinTo(separator, prefix, postfix, transform).toTypedArray()

View File

@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2g
kotlin_version=1.5.30 kotlin_version=1.5.30
kotlin_coroutines_version=1.5.1 kotlin_coroutines_version=1.5.1
kotlin_serialisation_core_version=1.2.2 kotlin_serialisation_core_version=1.2.2
kotlin_exposed_version=0.33.1 kotlin_exposed_version=0.34.1
ktor_version=1.6.3 ktor_version=1.6.3
@ -45,5 +45,5 @@ dokka_version=1.5.0
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.5.22 version=0.5.23
android_code_version=63 android_code_version=64