UI applications often need to maintain observable state.
The state is conceptually a time-changing variable that always has a value that can be observed by multiple views.
Currently, ConflatedBroadcastChannel
is used for such state representation but it is not very efficient,
because it has to provide full-blown implementation of SendChannel
for updating state and ReceiveChannel
for observing state, but far simpler concept is actually needed in practice.
There's a whole set of potential Flow
operators that maintain some kind of state for each active collection.
For example, Flow.withIndex
and conceptually similar operators.
Introduce withState
operator to simplify implementation for all kinds of stateful operators:
There's a whole set of potential Flow
operators that maintain some kind of state for each active collection.
For example, Flow.withIndex
and conceptually similar operators.
The proposal is to introduce a generic withState
operator to simplify implementation for all of them:
This file contains hidden or 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
import kotlinx.coroutines.* | |
import kotlin.coroutines.* | |
/** | |
* Scope interface to control (pause & resume) timeout | |
*/ | |
interface TimerScope : CoroutineScope { | |
fun pause() | |
fun resume() | |
} |
This file contains hidden or 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
https://drive.google.com/open?id=10_FO40m5KU4mW59vzS3KlL2Kb7zUWvEc |
This file contains hidden or 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
// ============ test functions ============ | |
fun withTransactional() = transactional { | |
println("withTransactional body") | |
} | |
fun withLogged() = logged { | |
println("withLogged body") | |
} |
This file contains hidden or 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
import kotlin.coroutines.* | |
import kotlin.coroutines.intrinsics.* | |
/** | |
* Defines deep recursive function that keeps its stack on the heap, | |
* which allows very deep recursive computations that do not use the actual call stack. | |
* To initiate a call to this deep recursive function use its [invoke] function. | |
* As a rule of thumb, it should be used if recursion goes deeper than a thousand calls. | |
* | |
* The [DeepRecursiveFunction] takes one parameter of type [T] and returns a result of type [R]. |
This file contains hidden or 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
import kotlin.coroutines.* | |
import kotlin.coroutines.intrinsics.* | |
/** | |
* Recursive computation engine for Kotlin that uses suspending functions to keep computation | |
* stack on the heap (as opposed to the real stack). | |
* | |
* This implementation is hardcoded for functions with two parameters [V1] and [V2] that | |
* return [R] as result, but it can be easily modified for functions with different | |
* number of parameters (see code). |
This file contains hidden or 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
/* | |
* Implementation of backward-mode automatic differentiation. | |
*/ | |
/** | |
* Differentiable variable with value and derivative of differentiation ([grad]) result | |
* with respect to this variable. | |
*/ | |
data class D(var x: Double, var d: Double = 0.0) { | |
constructor(x: Int): this(x.toDouble()) |
This file contains hidden or 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
package a; | |
public abstract class A { | |
abstract void foo(); | |
public void callFooA() { | |
System.out.print("callFooA: "); | |
foo(); | |
} | |
} |