This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement declarative wallet balance calculation
- Loading branch information
1 parent
9ad7b53
commit 60e95fb
Showing
6 changed files
with
92 additions
and
34 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.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,17 @@ | ||
package com.ivy.wallet.domain.action | ||
|
||
suspend infix fun <A, B> (suspend (A) -> List<B>).thenFilter( | ||
predicate: (B) -> Boolean | ||
): suspend (A) -> List<B> = | ||
{ a -> | ||
val list = this(a) | ||
list.filter(predicate) | ||
} | ||
|
||
suspend infix fun <A, B> (Action<A, List<B>>).thenFilter( | ||
predicate: (B) -> Boolean | ||
): suspend (A) -> List<B> = | ||
{ a -> | ||
val list = this(a) | ||
list.filter(predicate) | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.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,21 @@ | ||
package com.ivy.wallet.domain.action | ||
|
||
suspend infix fun <A, B, C> (suspend (A) -> List<B>).thenMap( | ||
transform: suspend (B) -> C | ||
): suspend (A) -> List<C> = | ||
{ a -> | ||
val list = this(a) | ||
list.map { | ||
transform(it) | ||
} | ||
} | ||
|
||
suspend infix fun <A, B, C> (Action<A, List<B>>).thenMap( | ||
transform: suspend (B) -> C | ||
): suspend (A) -> List<C> = | ||
{ a -> | ||
val list = this(a) | ||
list.map { | ||
transform(it) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.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,29 @@ | ||
package com.ivy.wallet.domain.action | ||
|
||
import java.math.BigDecimal | ||
|
||
suspend infix fun <A, B> (suspend (A) -> List<B>).thenSum( | ||
value: (B) -> BigDecimal | ||
): suspend (A) -> BigDecimal = | ||
{ a -> | ||
val list = this(a) | ||
list.fold( | ||
initial = BigDecimal.ZERO, | ||
operation = { acc, b -> | ||
acc + value(b) | ||
} | ||
) | ||
} | ||
|
||
suspend infix fun <A, B> (Action<A, List<B>>).thenSum( | ||
value: (B) -> BigDecimal | ||
): suspend (A) -> BigDecimal = | ||
{ a -> | ||
val list = this(a) | ||
list.fold( | ||
initial = BigDecimal.ZERO, | ||
operation = { acc, b -> | ||
acc + value(b) | ||
} | ||
) | ||
} |
9 changes: 0 additions & 9 deletions
9
app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt
This file was deleted.
Oops, something went wrong.
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
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