mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
commit
dc80ade2fb
@ -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`
|
||||
|
@ -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()
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user