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.
- Loading branch information
1 parent
8b22a51
commit 9ad7b53
Showing
10 changed files
with
94 additions
and
104 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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/ivy/wallet/domain/action/Composition.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,54 @@ | ||
package com.ivy.wallet.domain.action | ||
|
||
|
||
suspend infix fun <A, B, C> (suspend (A) -> B).then(f: suspend (B) -> C): suspend (A) -> C = | ||
{ a -> | ||
val b = this@then(a) | ||
f(b) | ||
} | ||
|
||
suspend infix fun <B, C> (suspend () -> B).then(f: suspend (B) -> C): suspend () -> C = | ||
{ | ||
val b = this@then() | ||
f(b) | ||
} | ||
|
||
suspend infix fun <A, B, C> (suspend (A) -> B).then(act: Action<B, C>): suspend (A) -> C = | ||
{ a -> | ||
val b = this@then(a) | ||
act(b) | ||
} | ||
|
||
suspend infix fun <B, C> (suspend () -> B).then(act: Action<B, C>): suspend () -> C = | ||
{ | ||
val b = this@then() | ||
act(b) | ||
} | ||
|
||
suspend infix fun <A, B, C> (Action<A, B>).then(f: suspend (B) -> C): suspend (A) -> C = | ||
{ a -> | ||
val b = this@then(a) | ||
f(b) | ||
} | ||
|
||
|
||
suspend infix fun <B, C> (() -> B).then(f: suspend (B) -> C): suspend () -> C = | ||
{ | ||
val b = this@then() | ||
f(b) | ||
} | ||
|
||
fun <C> (() -> C).fixUnit(): suspend (Unit) -> C = | ||
{ | ||
this() | ||
} | ||
|
||
fun <C> (suspend () -> C).fixUnit(): suspend (Unit) -> C = | ||
{ | ||
this() | ||
} | ||
|
||
fun <C> (suspend (Unit) -> C).fixUnit(): suspend () -> C = | ||
{ | ||
this(Unit) | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.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,9 @@ | ||
package com.ivy.wallet.domain.action | ||
|
||
suspend infix fun <A> (suspend (Any) -> List<A>).thenFilter( | ||
predicate: (A) -> Boolean | ||
): suspend (Any) -> List<A> = | ||
{ a -> | ||
val list = this(a) | ||
list.filter(predicate) | ||
} |
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,9 @@ | ||
package com.ivy.wallet.domain.action | ||
|
||
abstract class FPAction<I, O> : Action<I, O>() { | ||
protected abstract suspend fun I.recipe(): (suspend () -> O) | ||
protected abstract suspend fun I.compose(): (suspend () -> O) | ||
|
||
override suspend fun I.willDo(): O { | ||
return recipe().invoke() | ||
return compose().invoke() | ||
} | ||
} |
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
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
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