eygraber
12/11/2020, 8:10 PMvar current: Segment? = null
data
.segments
.find { segment ->
shouldSegmentBeShown()
.let { (meetsDependency, crossesFrequencyThreshold) ->
if(meetsDependency && !crossesFrequencyThreshold) {
current = segment
}
meetsDependency && crossesFrequencyThreshold
}
}
Nir
12/11/2020, 8:21 PMNir
12/11/2020, 8:23 PMNir
12/11/2020, 8:25 PMNir
12/11/2020, 8:26 PMmeetsDependency && !crossesFrequencyThreshold
, before finding something that meetsDependency && crossesFrequencyThreshold
eygraber
12/11/2020, 8:26 PMNir
12/11/2020, 8:26 PMeygraber
12/11/2020, 8:26 PMNir
12/11/2020, 8:29 PMNir
12/11/2020, 8:32 PMNir
12/11/2020, 8:40 PMval (current, last) = data
.segments.asSequence()
.map { it to shouldSegmentBeShown() }
.fold(Pair(null, null)) { ....
.takeWhile( ... )
.last()
Nir
12/11/2020, 8:41 PMshouldSegmentBeShown()
in two stepsNir
12/11/2020, 8:42 PMcurrent = segment
Nir
12/11/2020, 8:44 PMfind
(negated, I think). Basically, keep processing the sequence until this condition is no longer true. And then, we take the last element. That's basically the idea. Except, takeWhile might not even be quite right, you might need takeWhileInclusive..Nir
12/11/2020, 8:46 PMrun
block so that the net result is still clean from the outside:
val (current, last) = run {
....
}
Nir
12/11/2020, 8:47 PMNir
12/11/2020, 8:48 PMNir
12/11/2020, 8:57 PMval (current, last) = data.segments.asSequence()
.map { it to shouldSegmentBeShown() }
.takeWhileInclusive { (segment, shouldShow) ->
val (meetsDep, crossesFreq) = shouldShow
!(meetsDep && crossesFreq)
}.fold(Pair(null, null)) { acc, t ->
val (segment, shouldShow) = t
val (meetsDep, crossesFreq) = ShouldShow
Pair( if(meetsDep && !crossesFreq) segment else acc.first, segment)
}.last()
Nir
12/11/2020, 8:58 PMNir
12/11/2020, 8:59 PMeygraber
12/13/2020, 10:23 AM