Updated on 2026-08-14

This commit is contained in:
Tangem 2023-04-19 18:48:28 +03:00
parent 9b852c9452
commit c3d8722f57
6 changed files with 51 additions and 0 deletions

1
domain/core/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,10 @@
plugins {
alias(deps.plugins.kotlin.jvm)
id("configuration")
}
dependencies {
api(deps.kotlin.coroutines)
api(deps.arrow.core)
api(deps.arrow.fx)
}

View file

@ -0,0 +1,7 @@
package com.tangem.domain.core.chain
import arrow.core.Either
interface Chain<E, R> {
suspend operator fun invoke(previousChainResult: Either<E, R>): Either<E, R>
}

View file

@ -0,0 +1,28 @@
package com.tangem.domain.core.chain
import arrow.core.Either
class ChainProcessor<E, R> {
private val chains: MutableList<Chain<E, R>> = mutableListOf()
fun addChains(vararg chains: Chain<E, R>) {
this.chains.addAll(chains)
}
suspend fun launchChains(initial: R, returnOnFirstError: Boolean = true): Either<E, R> {
return launchChains(initial = Either.Right(initial), returnOnFirstError)
}
private suspend fun launchChains(initial: Either<E, R>, returnOnFirstError: Boolean = true): Either<E, R> {
var result = initial
chains.forEach { chain ->
result = chain(result)
.onRight {
if (returnOnFirstError) return result
}
}
return result
}
}

View file

@ -68,6 +68,7 @@ zxingQrBarcodeScanner = "1.9.8"
zxingQrCode = "3.5.1" zxingQrCode = "3.5.1"
mviCore = "1.3.1" mviCore = "1.3.1"
kotlinSerialization = "1.4.1" kotlinSerialization = "1.4.1"
arrow = "1.2.0-RC"
# endregion Other libraries # endregion Other libraries
# region Tangem # region Tangem
@ -206,4 +207,6 @@ zxing-qrBarcodeScanner = { module = "me.dm7.barcodescanner:zxing", version.ref =
zxing-qrCore = { module = "com.google.zxing:core", version.ref = "zxingQrCode" } zxing-qrCore = { module = "com.google.zxing:core", version.ref = "zxingQrCode" }
mviCore-watcher = { module = "com.github.badoo.mvicore:mvicore-diff", version.ref = "mviCore" } mviCore-watcher = { module = "com.github.badoo.mvicore:mvicore-diff", version.ref = "mviCore" }
kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinSerialization" } kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinSerialization" }
arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
arrow-fx = { module = "io.arrow-kt:arrow-fx-coroutines", version.ref = "arrow" }
# endregion Other # endregion Other

View file

@ -62,4 +62,6 @@ include(":features:tester:impl")
// TODO: Remove, temporary modules // TODO: Remove, temporary modules
include(":domain:models") include(":domain:models")
include(":domain:legacy") include(":domain:legacy")
include(":domain:core")
// endregion Domain modules // endregion Domain modules