Say I have this:
class NumWithSuccessor {
var num = 1
val successor
get() = num + 1
}
Now, if I want an array of nums instead,
class NumsWithSuccessors {
var nums = Array<Int>(3){ 1 }
val successor
get() = /* What? */
}
My first guess is to use
get() = { Array<Int>(3){ nums[it] + 1 } }
But that would lead to creation of a new array every time I need to access a successor. Is there a simple, better way?
Practical Example:
// Need to go from this...
private val _dayWiseEventsList = // For internal use
MediatorLiveData<List<Event>>()
val dayWiseEventsList: LiveData<List<Event>> // For immutable, external observation
get() = _dayWiseEventsList
// ... to this
private val _dayWiseEventsListArray = // For internal use
Array<MediatorLiveData<List<Event>>>(DAYS) { MediatorLiveData() }
val dayWiseEventsListArray // For immutable, external observation
// Need an alternative for this
get() = Array<LiveData<List<Event>>>(DAYS) { _dayWiseEventsListArray[it] }