mjthornton
04/14/2020, 5:36 PMShawn
04/14/2020, 5:41 PMShawn
04/14/2020, 5:41 PM.firstOrNull()
Shawn
04/14/2020, 5:42 PMval foo = list.firstOrNull() ?: default
Shawn
04/14/2020, 5:48 PMlist.firstOrNull()?.let {
doSomethingWithValue(it)
}
but that’s not too different from just doing this
if (list.isNotEmpty()) {
doSomethingWithValue(list[0])
}
mjthornton
04/14/2020, 5:56 PMShawn
04/14/2020, 5:59 PMmjthornton
04/14/2020, 5:59 PMmjthornton
04/14/2020, 5:59 PMmjthornton
04/14/2020, 5:59 PMShawn
04/14/2020, 6:00 PMShawn
04/14/2020, 6:00 PMmjthornton
04/14/2020, 6:01 PMlineData.dataSets.filter{ it.label == "Bolus"}?.let {
for(index in it.indices){
// TODO: Safe Array Index access
val entry = it.get(index).getEntryForIndex(0)
withinRangeOfBolus(entry, xCoordinate, yCoordinate, xRange, yRange)
}
}
mjthornton
04/14/2020, 6:01 PMval entry = it.get(index).getEntryForIndex(0)
mjthornton
04/14/2020, 6:02 PMmjthornton
04/14/2020, 6:02 PMShawn
04/14/2020, 6:04 PMShawn
04/14/2020, 6:04 PMShawn
04/14/2020, 6:04 PMwithinRangeOfBolus()
just return Unit
?mjthornton
04/14/2020, 6:04 PMmjthornton
04/14/2020, 6:05 PMmjthornton
04/14/2020, 6:05 PMwithinRangeOfBolus()
just return Unit
? --> BooleanShawn
04/14/2020, 6:07 PMShawn
04/14/2020, 6:09 PMShawn
04/14/2020, 6:10 PMwithinRangeOfBolus()
? in your snippet you’re not assigning it to anything or returning itmjthornton
04/14/2020, 6:24 PMmjthornton
04/14/2020, 6:24 PMlineData.dataSets.filter{ it.label == "Bolus"}?.let {
for(index in it.indices){
it.get(index).run {
if(entryCount > 0) {
val entry = this.getEntryForIndex(0)
withinRangeOfBolus(entry, xCoordinate, yCoordinate, xRange, yRange)
}
}
}
}
mjthornton
04/14/2020, 6:24 PMShawn
04/14/2020, 6:24 PMdataSets.filter {
it.label == "Bolus"
&& it.entries.isNotEmpty()
&& withinRangeOfBolus(it.entries.first(), xCoordinate, yCoordinate, xRange, yRange)
}
if you’re looking to filter for all entries that are within range, then this would be closer:
val entryList: List<Entry> = dataSets.asSequence()
.filter {
it.label == "Bolus"
&& it.entries.isNotEmpty()
&& withinRangeOfBolus(it.entries.first(), xCoordinate, yCoordinate, xRange, yRange
)
}
.map { it.entries }
.flatten()
.toList()
mjthornton
04/14/2020, 6:26 PMmjthornton
04/14/2020, 6:26 PMmjthornton
04/14/2020, 6:31 PMmjthornton
04/14/2020, 6:33 PM//graphedBoluses = {ArrayList@14219} size = 4
// 0 = {LineDataSet@14302} "DataSet, label: Bolus, entries: 2\nEntry, x: 6883.0 y: -40.0 Entry, x: 7483.0 y: -40.0 "
// 1 = {LineDataSet@14303} "DataSet, label: Bolus, entries: 3\nEntry, x: 9097.0 y: -34.0 Entry, x: 9697.0 y: -34.0 Entry, x: 10061.0 y: -34.0 "
// 2 = {LineDataSet@14304} "DataSet, label: Bolus, entries: 3\nEntry, x: 28093.0 y: -10.68 Entry, x: 28693.0 y: -10.68 Entry, x: 29196.0 y: -10.68 "
// 3 = {LineDataSet@14305} "DataSet, label: Bolus, entries: 2\nEntry, x: 85879.0 y: -27.32 Entry, x: 86479.0 y: -27.32 "
// EachLineDataSet has an mValues: ArrayList<Entry>..
//mValues = {ArrayList@14368} size = 3
// 0 = {Entry@14375} "Entry, x: 28093.0 y: -10.68"
// x = 28093.0
// mData = {BolusDisplayModel@14381} "Entry, x: 28093.0 y: 8.33"
// mIcon = null
// y = -10.68
// shadow$_klass_ = {Class@12944} "class com.github.mikephil.charting.data.Entry"
// shadow$_monitor_ = 0
// 1 = {Entry@14376} "Entry, x: 28693.0 y: -10.68"
// 2 = {Entry@14377} "Entry, x: 29196.0 y: -10.68"
// 1. Filter the events by "Bolus"... This gives you the lineDataSets
// 2. Loop through the LineDataSet via index.
// 2a. Grab the first entry... This will be the starting entry... Should check to make sure there is an Entry to be safe
// 2b. To get the center point, we should add width & height
mjthornton
04/14/2020, 6:33 PMShawn
04/14/2020, 6:33 PM&&
is short-circuiting, withinRangeOfBolus
doesn’t get called if either conditions to its left evaluate to falsemjthornton
04/14/2020, 6:34 PMShawn
04/14/2020, 6:34 PMShawn
04/14/2020, 6:35 PMmjthornton
04/14/2020, 6:43 PMmjthornton
04/14/2020, 6:45 PMmjthornton
04/14/2020, 6:46 PMmjthornton
04/14/2020, 6:47 PMShawn
04/14/2020, 6:48 PMmjthornton
04/14/2020, 6:50 PMShawn
04/14/2020, 6:52 PMmjthornton
04/14/2020, 6:53 PMmjthornton
04/14/2020, 6:53 PMShawn
04/14/2020, 6:53 PMmjthornton
04/14/2020, 6:53 PMShawn
04/14/2020, 6:54 PMShawn
04/14/2020, 6:54 PMmjthornton
04/14/2020, 6:54 PMmjthornton
04/14/2020, 6:54 PMmjthornton
04/14/2020, 6:54 PM