Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Publish Dev Guidelines v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 9, 2022
1 parent 2b6ed50 commit f57c982
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/ivy/wallet/utils/DateExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ivy.wallet.utils

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import com.ivy.fp.Total
import com.ivy.wallet.R
import com.ivy.wallet.stringRes
import java.time.*
Expand All @@ -13,8 +14,10 @@ import java.util.concurrent.TimeUnit

fun timeNowLocal() = LocalDateTime.now()

@Total
fun timeNowUTC(): LocalDateTime = LocalDateTime.now(ZoneOffset.UTC)

@Total
fun dateNowUTC(): LocalDate = LocalDate.now(ZoneOffset.UTC)

fun startOfDayNowUTC() = dateNowUTC().atStartOfDay()
Expand Down
72 changes: 64 additions & 8 deletions docs/Developer-Guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ A short guide _(that'll evolve with time)_ with one and only goal - to **make us
> Proposals: Highly appreciated. :rocket:
> PRs for typos, better wording, better examples or minor edits are also very welcome!
## Ivy Architecture (FRP)

The Ivy Architecture follows the Functional Reactive Programming (FRP) principles. A good example for them is [The Elm Architecture.](https://guide.elm-lang.org/architecture/)
Expand Down Expand Up @@ -305,18 +307,46 @@ class OverdueAct @Inject constructor(
### 4. Pure (domain logic with pure code)

The `pure` layer as the name suggests must consist of only pure functions without side-effects. If the business logic requires, **side-effects must be abstracted**.
The `pure` layer must consist of only pure functions without side-effects. If the business logic requires, **side-effects must be abstracted**.

**Motivation**
- Without the `pure` package many `actions` would duplicate the same code because of the different side-effects => `pure` offers re-usability of tested and working functions.

**Function types**
- Partial: not defined for all input values
- **Partial**: not defined for all input values
```Kotlin
@Partial(inCaseOf="b = 0, produces ArithmeticException::class")
@Partial(inCaseOf="b=0, produces ArithmeticException::class")
fun divide(a: Int, b: Int) = a / b
```
- Total: defined for all input values but with side-effects
- **Total**: defined for all input values but for the same input isn't guarantee to always return the same output (has side-effects)
```Kotlin
//It's defined in all cases but with each call returns a different output
@Total
fun timeNowUTC(): LocalDateTime = LocalDateTime.now(ZoneOffset.UTC)

//Produdes logging side-effect which can be seen in Logcat
@Total
fun
fun logMessage(
msg: String
) {
Log.d("DEBUG", msg) //SIDE-EFFECT!
}
```

- **Pure**: defined for all input values and for the same input always returns the same result (has NO side-effects)
```Kotlin
@Pure
fun sum(a: Int, b: Int) = a + b

@Pure
fun logMessage(
msg: String,

@SideEffect
log: (String) -> Unit
) {
log("DEBUG: $msg")
}
```

Each `@Pure` function must be **total** and its `@SideEffect`(s) if any abstracted.
Expand All @@ -343,7 +373,7 @@ pure -- Calculates --> output

**Code Example**
```Kotlin
//domain.action
//domain.action (NOT PURE)
class ExchangeAct @Inject constructor(
private val exchangeRateDao: ExchangeRateDao,
) : FPAction<ExchangeAct.Input, Option<BigDecimal>>() {
Expand All @@ -364,7 +394,7 @@ class ExchangeAct @Inject constructor(
}


//domain.pure
//domain.pure (PURE)
@Pure
suspend fun exchange(
data: ExchangeData,
Expand Down Expand Up @@ -426,6 +456,32 @@ Responsible for the interaction with the Android System like launching `Intent`,

---

_Version 1.0.0_
## Testing

One of the reasons for the Ivy Architecture is to support painless, effective and efficient testing of the code base.

### Unit Testing

- `Data Model`
- `Pure`

### Property-Based Testing

- `Data Model`
- `Pure`

### End-to-end Android Tests

- `Action`
- `IO`
- `Android System`

### UI Android Tests

- `UI` (Compose)

---

_Version 1.1.1_

_Feedback and proposals are highly appreciated! Let's spark techincal discussion and make Ivy and the Android World better! :rocket:_

0 comments on commit f57c982

Please sign in to comment.