Compare commits

..

18 Commits
0.9.1 ... 0.9.6

Author SHA1 Message Date
87a3f61ca6 fix in ExposedOneToManyKeyValueRepo 2022-02-07 20:43:43 +06:00
506e937a68 start 0.9.6 2022-02-07 20:39:44 +06:00
5a037c76dd Merge pull request #126 from InsanusMokrassar/0.9.5
0.9.5
2022-02-01 23:30:26 +06:00
313f622f7e Update CHANGELOG.md 2022-02-01 14:27:07 +06:00
6cba1fe1a2 Update klock 2022-02-01 14:25:24 +06:00
fd2d0e80b7 start 0.9.5 2022-02-01 14:24:12 +06:00
96ab2e8aca Merge pull request #125 from InsanusMokrassar/0.9.4
0.9.4
2022-01-18 18:58:49 +06:00
0202988cae several fixes in optionallyReverse 2022-01-17 16:11:55 +06:00
d619d59947 Either updates 2022-01-17 15:56:48 +06:00
85b3e48d18 add optionallyReverse extensions 2022-01-17 15:38:23 +06:00
7a9b7d98a1 start 0.9.4 2022-01-14 13:22:04 +06:00
b212acfcaf Merge pull request #124 from InsanusMokrassar/0.9.3
0.9.3
2022-01-14 00:46:20 +06:00
3a45e5dc70 Update CHANGELOG.md 2022-01-14 00:37:03 +06:00
73190518d5 Update gradle.properties 2022-01-14 00:35:51 +06:00
03f78180dc Merge pull request #123 from InsanusMokrassar/0.9.2
0.9.2
2022-01-13 11:22:54 +06:00
1c0b8cf842 Update CHANGELOG.md 2022-01-13 10:20:35 +06:00
a1624ea2a9 Update gradle.properties 2022-01-13 10:19:08 +06:00
23a050cf1e Merge pull request #122 from InsanusMokrassar/0.9.1
0.9.1
2022-01-08 16:12:04 +06:00
6 changed files with 111 additions and 19 deletions

View File

@@ -1,5 +1,37 @@
# Changelog # Changelog
## 0.9.6
* `Repos`:
* `Exposed`:
* Fix in `ExposedOneToManyKeyValueRepo` - now it will not use `deleteIgnoreWhere`
## 0.9.5
* `Versions`:
* `Klock`: `2.4.12` -> `2.4.13`
## 0.9.4
* `Pagination`:
* `Common`:
* Add several `optionallyReverse` functions
* `Common`:
* Changes in `Either`:
* Now `Either` uses `optionalT1` and `optionalT2` as main properties
* `Either#t1` and `Either#t2` are deprecated
* New extensions `Either#mapOnFirst` and `Either#mapOnSecond`
## 0.9.3
* `Versions`:
* `UUID`: `0.3.1` -> `0.4.0`
## 0.9.2
* `Versions`:
* `Klock`: `2.4.10` -> `2.4.12`
## 0.9.1 ## 0.9.1
* `Repos`: * `Repos`:

View File

@@ -6,7 +6,7 @@ import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.* import kotlinx.serialization.encoding.*
/** /**
* Realization of this interface will contains at least one not null - [t1] or [t2] * Realization of this interface will contains at least one not null - [optionalT1] or [optionalT2]
* *
* @see EitherFirst * @see EitherFirst
* @see EitherSecond * @see EitherSecond
@@ -14,11 +14,19 @@ import kotlinx.serialization.encoding.*
* @see Either.Companion.second * @see Either.Companion.second
* @see Either.onFirst * @see Either.onFirst
* @see Either.onSecond * @see Either.onSecond
* @see Either.mapOnFirst
* @see Either.mapOnSecond
*/ */
@Serializable(EitherSerializer::class) @Serializable(EitherSerializer::class)
sealed interface Either<T1, T2> { sealed interface Either<T1, T2> {
val optionalT1: Optional<T1>
val optionalT2: Optional<T2>
@Deprecated("Use optionalT1 instead", ReplaceWith("optionalT1"))
val t1: T1? val t1: T1?
get() = optionalT1.dataOrNull()
@Deprecated("Use optionalT2 instead", ReplaceWith("optionalT2"))
val t2: T2? val t2: T2?
get() = optionalT2.dataOrNull()
companion object { companion object {
fun <T1, T2> serializer( fun <T1, T2> serializer(
@@ -93,25 +101,25 @@ class EitherSerializer<T1, T2>(
} }
/** /**
* This type [Either] will always have not nullable [t1] * This type [Either] will always have not nullable [optionalT1]
*/ */
@Serializable @Serializable
data class EitherFirst<T1, T2>( data class EitherFirst<T1, T2>(
override val t1: T1 override val t1: T1
) : Either<T1, T2> { ) : Either<T1, T2> {
override val t2: T2? override val optionalT1: Optional<T1> = t1.optional
get() = null override val optionalT2: Optional<T2> = Optional.absent()
} }
/** /**
* This type [Either] will always have not nullable [t2] * This type [Either] will always have not nullable [optionalT2]
*/ */
@Serializable @Serializable
data class EitherSecond<T1, T2>( data class EitherSecond<T1, T2>(
override val t2: T2 override val t2: T2
) : Either<T1, T2> { ) : Either<T1, T2> {
override val t1: T1? override val optionalT1: Optional<T1> = Optional.absent()
get() = null override val optionalT2: Optional<T2> = t2.optional
} }
/** /**
@@ -124,23 +132,35 @@ inline fun <T1, T2> Either.Companion.first(t1: T1): Either<T1, T2> = EitherFirst
inline fun <T1, T2> Either.Companion.second(t2: T2): Either<T1, T2> = EitherSecond(t2) inline fun <T1, T2> Either.Companion.second(t2: T2): Either<T1, T2> = EitherSecond(t2)
/** /**
* Will call [block] in case when [Either.t1] of [this] is not null * Will call [block] in case when [this] is [EitherFirst]
*/ */
inline fun <T1, T2, E : Either<T1, T2>> E.onFirst(block: (T1) -> Unit): E { inline fun <T1, T2, E : Either<T1, T2>> E.onFirst(block: (T1) -> Unit): E {
val t1 = t1 optionalT1.onPresented(block)
t1 ?.let(block)
return this return this
} }
/** /**
* Will call [block] in case when [Either.t2] of [this] is not null * Will call [block] in case when [this] is [EitherSecond]
*/ */
inline fun <T1, T2, E : Either<T1, T2>> E.onSecond(block: (T2) -> Unit): E { inline fun <T1, T2, E : Either<T1, T2>> E.onSecond(block: (T2) -> Unit): E {
val t2 = t2 optionalT2.onPresented(block)
t2 ?.let(block)
return this return this
} }
/**
* @return Result of [block] if [this] is [EitherFirst]
*/
inline fun <T1, R> Either<T1, *>.mapOnFirst(block: (T1) -> R): R? {
return optionalT1.mapOnPresented(block)
}
/**
* @return Result of [block] if [this] is [EitherSecond]
*/
inline fun <T2, R> Either<*, T2>.mapOnSecond(block: (T2) -> R): R? {
return optionalT2.mapOnPresented(block)
}
inline fun <reified T1, reified T2> Any.either() = when (this) { inline fun <reified T1, reified T2> Any.either() = when (this) {
is T1 -> Either.first<T1, T2>(this) is T1 -> Either.first<T1, T2>(this)
is T2 -> Either.second<T1, T2>(this) is T2 -> Either.second<T1, T2>(this)

View File

@@ -14,11 +14,11 @@ kotlin_exposed_version=0.37.2
ktor_version=1.6.7 ktor_version=1.6.7
klockVersion=2.4.10 klockVersion=2.4.13
github_release_plugin_version=2.2.12 github_release_plugin_version=2.2.12
uuidVersion=0.3.1 uuidVersion=0.4.0
# ANDROID # ANDROID
@@ -40,10 +40,10 @@ crypto_js_version=4.1.1
# Dokka # Dokka
dokka_version=1.6.0 dokka_version=1.6.10
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.9.1 version=0.9.6
android_code_version=91 android_code_version=96

View File

@@ -38,3 +38,31 @@ fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
size.toLong() size.toLong()
) )
} }
fun <T> Iterable<T>.optionallyReverse(reverse: Boolean): Iterable<T> = when (this) {
is List<T> -> optionallyReverse(reverse)
is Set<T> -> optionallyReverse(reverse)
else -> if (reverse) {
reversed()
} else {
this
}
}
fun <T> List<T>.optionallyReverse(reverse: Boolean): List<T> = if (reverse) {
reversed()
} else {
this
}
fun <T> Set<T>.optionallyReverse(reverse: Boolean): Set<T> = if (reverse) {
reversed().toSet()
} else {
this
}
inline fun <reified T> Array<T>.optionallyReverse(reverse: Boolean) = if (reverse) {
Array(size) {
get(lastIndex - it)
}
} else {
this
}

View File

@@ -26,3 +26,15 @@ fun Pagination.reverse(datasetSize: Long): SimplePagination {
* Shortcut for [reverse] * Shortcut for [reverse]
*/ */
fun Pagination.reverse(objectsCount: Int) = reverse(objectsCount.toLong()) fun Pagination.reverse(objectsCount: Int) = reverse(objectsCount.toLong())
fun Pagination.optionallyReverse(objectsCount: Int, reverse: Boolean) = if (reverse) {
reverse(objectsCount)
} else {
this
}
fun Pagination.optionallyReverse(objectsCount: Long, reverse: Boolean) = if (reverse) {
reverse(objectsCount)
} else {
this
}

View File

@@ -48,7 +48,7 @@ open class ExposedOneToManyKeyValueRepo<Key, Value>(
transaction(database) { transaction(database) {
toRemove.keys.flatMap { k -> toRemove.keys.flatMap { k ->
toRemove[k] ?.mapNotNull { v -> toRemove[k] ?.mapNotNull { v ->
if (deleteIgnoreWhere { keyColumn.eq(k).and(valueColumn.eq(v)) } > 0 ) { if (deleteWhere { keyColumn.eq(k).and(valueColumn.eq(v)) } > 0 ) {
k to v k to v
} else { } else {
null null