Skip to content

Commit

Permalink
KMM :: Internal :: Add arrow library
Browse files Browse the repository at this point in the history
  • Loading branch information
franmontiel committed Aug 29, 2023
1 parent f914802 commit a12e74f
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 227 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ subprojects {
}

ktlint {
version.set("0.50.0")
verbose.set(true)
outputToConsole.set(true)
filter {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Android config
const val android_min_sdk_version = 21
const val android_target_sdk_version = 33
const val android_target_sdk_version = 34


34 changes: 18 additions & 16 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
[versions]
kotlin = "1.8.0"
arrowCore = "1.2.0"
kotlin = "1.8.22"
# Plugins
androidGradlePlugin = "7.4.0"
detekt = "1.22.0"
gradleVersions = "0.44.0"
ksp = "1.8.0-1.0.8"
ktlint = "11.0.0"
ksp = "1.8.22-1.0.11"
ktlint = "11.5.1"
taskTree = "2.1.1"
versionCatalogUpdate = "0.7.0"
# KMM
coroutines = "1.6.4"
coroutines = "1.7.3"
datetime = "0.4.0"
ktor = "2.2.2"
serialization = "1.4.1"
ktor = "2.2.4"
serialization = "1.5.0"
sqldelight = "1.5.5"
uuidLib = "0.6.0"
# Android
activityCompose = "1.6.1"
appCompat = "1.6.0"
activityCompose = "1.7.2"
appCompat = "1.6.1"
bugfender = "3.1.0"
compose = "1.3.3"
composeCompiler = "1.4.0"
compose = "1.5.0"
composeCompiler = "1.4.8"
composeDestinations = "1.7.32-beta"
composeMaterial = "1.3.1"
composeMaterial = "1.5.0"
constraintLayout = "2.1.4"
coordinatorLayout = "1.2.0"
coreKtx = "1.9.0"
coreKtx = "1.10.1"
gson = "2.9.1"
lifecycle = "2.5.1"
material = "1.7.0"
lifecycle = "2.6.1"
material = "1.9.0"
# Testing
androidxJunitKtx = "1.1.5"
androidxTest = "1.5.0"
junit = "4.13.2"
lifecycleRuntime = "2.5.1"
mockk = "1.13.3"
lifecycleRuntime = "2.6.1"
mockk = "1.13.5"
mockmp = "1.11.0"
roboelectric = "4.9.2"

[libraries]
# KMM
arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrowCore" }
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
Expand Down
1 change: 1 addition & 0 deletions harmony-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ kotlin {
api(libs.bundles.ktor)
api(libs.datetime)
implementation(libs.uuidLib)
api(libs.arrow.core)
}
}
val commonTest by getting {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.harmony.kotlin.domain.interactor.either

import com.harmony.kotlin.common.either.Either
import com.harmony.kotlin.common.either.eitherOf
import arrow.core.Either
import com.harmony.kotlin.data.operation.DefaultOperation
import com.harmony.kotlin.data.operation.Operation
import com.harmony.kotlin.data.query.Query
Expand All @@ -17,7 +16,9 @@ class GetInteractor<M>(val coroutineContext: CoroutineContext, val getRepository

suspend inline operator fun <reified E : HarmonyException> invoke(query: Query = VoidQuery, operation: Operation = DefaultOperation): Either<E, M> =
withContext(coroutineContext) {
eitherOf { getRepository.get(query, operation) }
Either.catchOrThrow {
getRepository.get(query, operation)
}
}
}

Expand All @@ -26,18 +27,18 @@ class PutInteractor<M>(val coroutineContext: CoroutineContext, val putRepository
suspend inline operator fun <reified E : HarmonyException> invoke(
m: M? = null,
query: Query = VoidQuery,
operation: Operation = DefaultOperation
operation: Operation = DefaultOperation,
): Either<E, M> =
withContext(coroutineContext) {
eitherOf { putRepository.put(query, m, operation) }
Either.catchOrThrow { putRepository.put(query, m, operation) }
}
}

class DeleteInteractor(val coroutineContext: CoroutineContext, val deleteRepository: DeleteRepository) {

suspend inline operator fun <reified E : HarmonyException> invoke(query: Query = VoidQuery, operation: Operation = DefaultOperation): Either<E, Unit> =
withContext(coroutineContext) {
eitherOf { deleteRepository.delete(query, operation) }
Either.catchOrThrow { deleteRepository.delete(query, operation) }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mobilejazz.kmmsample.core.feature.hackerposts.domain.interactor

import com.harmony.kotlin.common.either.Either
import arrow.core.Either
import com.harmony.kotlin.domain.interactor.either.GetInteractor
import com.harmony.kotlin.error.HarmonyException
import com.mobilejazz.kmmsample.core.feature.hackerposts.domain.HackerNewsQuery
Expand All @@ -10,7 +10,7 @@ import kotlin.coroutines.CoroutineContext

class GetHackerNewsPostInteractor(
private val coroutineContext: CoroutineContext,
private val getHackerNewsPostInteractor: GetInteractor<HackerNewsPost>
private val getHackerNewsPostInteractor: GetInteractor<HackerNewsPost>,
) {

suspend operator fun invoke(hackerNewsPostId: Long): Either<HarmonyException, HackerNewsPost> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.mobilejazz.kmmsample.core.feature.hackerposts.domain.interactor

import com.harmony.kotlin.common.either.Either
import com.harmony.kotlin.common.either.asSingleEither
import com.harmony.kotlin.common.either.flatMap
import arrow.core.Either
import arrow.core.raise.either
import com.harmony.kotlin.domain.interactor.either.GetInteractor
import com.harmony.kotlin.error.HarmonyException
import com.mobilejazz.kmmsample.core.feature.hackerposts.domain.HackerNewsQuery
Expand All @@ -15,18 +14,17 @@ import kotlin.coroutines.CoroutineContext
class GetHackerNewsPostsInteractor(
private val coroutineContext: CoroutineContext,
private val getHackerNewsIdsPostsInteractor: GetInteractor<HackerNewsPostsIds>,
private val getHackerNewsPostInteractor: GetInteractor<HackerNewsPost>
private val getHackerNewsPostInteractor: GetInteractor<HackerNewsPost>,
) {
suspend operator fun invoke(): Either<HarmonyException, HackerNewsPosts> {
return withContext(coroutineContext) {
getHackerNewsIdsPostsInteractor<HarmonyException>(
HackerNewsQuery.GetAll
).flatMap {
it.listIds.take(5).map { postId ->
getHackerNewsPostInteractor<HarmonyException>(
HackerNewsQuery.GetPost(postId)
)
}.asSingleEither()
either {
getHackerNewsIdsPostsInteractor<HarmonyException>(HackerNewsQuery.GetAll).bind()
.listIds
.take(5)
.map { postId ->
getHackerNewsPostInteractor<HarmonyException>(HackerNewsQuery.GetPost(postId)).bind()
}
}
}
}
Expand Down
Loading

0 comments on commit a12e74f

Please sign in to comment.