v79
04/07/2025, 8:13 PMhexes.filter { it.hexData != null }
.first { it.hexData.row == newHexData.row && it.hexData.column == newHexData.column }
Any suggestions? Ideally without creating a new list of hexes?Joffrey
04/07/2025, 8:15 PMfirst
lambda, and ditch the filter
Joffrey
04/07/2025, 8:16 PMv79
04/07/2025, 8:18 PMhexes.first { it.hexData != null && it.hexData.row == newHexData.row && it.hexData.column == newHexData.column }
v79
04/07/2025, 8:23 PM!!
for me to add 😞 It's for a game written with Godot, so there are loads of !!
already.Youssef Shoaib [MOD]
04/07/2025, 8:37 PMhexes.mapNotNull { it.hexData }.first { it.row == newHexData.row && it.column == newHexData.column }
Daniel Pitts
04/07/2025, 8:56 PMDaniel Pitts
04/07/2025, 8:57 PMhexes.first {
it.hexData?.run { row == newHJexData.row && column = newHexData.column } == true
}
v79
04/07/2025, 8:59 PM?.let
often enough, tend to forget about run
.Daniel Pitts
04/07/2025, 8:59 PMit
outside would be different than it
inside, and that's just ugly 😉Daniel Pitts
04/07/2025, 9:02 PMclass HexData(...) {
fun isSameCellAs(other: HexData):Boolean { ... }
}
Then : hexes.first { it.hexData?.isSameCellAs(newHexData) }