Skip to content

Instantly share code, notes, and snippets.

@volodymyr-sch
Created October 18, 2021 15:20
Show Gist options
  • Select an option

  • Save volodymyr-sch/d2befeadb7217e509ed6ca62539b3db2 to your computer and use it in GitHub Desktop.

Select an option

Save volodymyr-sch/d2befeadb7217e509ed6ca62539b3db2 to your computer and use it in GitHub Desktop.
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