-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create core interfaces for application
Signed-off-by: Yurii Surzhykov <yurii.surzhykov@nortekcontrol.com>
- Loading branch information
Yurii Surzhykov
committed
May 23, 2024
1 parent
96dd7da
commit 5897c9e
Showing
6 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
plugins { | ||
id("java-library") | ||
alias(libs.plugins.jetbrains.kotlin.jvm) | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_19 | ||
targetCompatibility = JavaVersion.VERSION_19 | ||
} | ||
|
||
dependencies { | ||
implementation(libs.kotlinx.coroutines.core) | ||
} |
4 changes: 3 additions & 1 deletion
4
...m/github/yuriisurzhykov/purs/core/Core.kt → .../github/yuriisurzhykov/purs/core/Clear.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package com.github.yuriisurzhykov.purs.core | ||
|
||
class Core { | ||
interface Clear { | ||
|
||
fun clear() | ||
} |
37 changes: 37 additions & 0 deletions
37
core/src/main/java/com/github/yuriisurzhykov/purs/core/Dispatchers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.yuriisurzhykov.purs.core | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
|
||
interface Dispatchers { | ||
|
||
fun launchUi(scope: CoroutineScope, block: suspend CoroutineScope.() -> Unit): Job | ||
fun launchBackground(scope: CoroutineScope, block: suspend CoroutineScope.() -> Unit): Job | ||
suspend fun switchToUi(block: suspend CoroutineScope.() -> Unit) | ||
|
||
abstract class Abstract( | ||
private val uiScope: CoroutineDispatcher, | ||
private val backgroundScope: CoroutineDispatcher | ||
) : Dispatchers { | ||
override fun launchUi( | ||
scope: CoroutineScope, | ||
block: suspend CoroutineScope.() -> Unit | ||
): Job = scope.launch(uiScope, block = block) | ||
|
||
override fun launchBackground( | ||
scope: CoroutineScope, | ||
block: suspend CoroutineScope.() -> Unit | ||
): Job = scope.launch(backgroundScope, block = block) | ||
|
||
override suspend fun switchToUi(block: suspend CoroutineScope.() -> Unit) = | ||
withContext(uiScope, block) | ||
} | ||
|
||
class Base : Abstract( | ||
uiScope = kotlinx.coroutines.Dispatchers.Main, | ||
backgroundScope = kotlinx.coroutines.Dispatchers.Default | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
core/src/main/java/com/github/yuriisurzhykov/purs/core/Mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.yuriisurzhykov.purs.core | ||
|
||
interface Mapper<S, R> { | ||
|
||
fun map(source: S): R | ||
|
||
interface Unit<T> : Mapper<T, Unit<T>> | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/com/github/yuriisurzhykov/purs/core/Read.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.yuriisurzhykov.purs.core | ||
|
||
interface Read<T> { | ||
|
||
fun read(): T | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/com/github/yuriisurzhykov/purs/core/Save.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.yuriisurzhykov.purs.core | ||
|
||
interface Save<T> { | ||
|
||
fun save(data: T) | ||
} |