Created
October 18, 2021 15:20
-
-
Save volodymyr-sch/d2befeadb7217e509ed6ca62539b3db2 to your computer and use it in GitHub Desktop.
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
| interface TimeCapsule<S : UiState> { | |
| fun addState(state: S) | |
| fun selectState(position: Int) | |
| fun getStates(): List<S> | |
| } | |
| class TimeTravelCapsule<S : UiState>( | |
| private val onStateSelected: (S) -> Unit | |
| ) : TimeCapsule<S> { | |
| private val states = mutableListOf<S>() | |
| override fun addState(state: S) { | |
| states.add(state) | |
| } | |
| override fun selectState(position: Int) { | |
| onStateSelected(states[position]) | |
| } | |
| override fun getStates(): List<S> { | |
| return states | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment