Travis Griggs
09/16/2021, 2:36 AMval candidates = listOf(
Pair(DragCyclePositionGesture::proximity, ::DragCyclePositionGesture),
Pair(DragMoveGesture::proximity, ::DragMoveGesture),
Pair(DragBeginGesture::proximity, ::DragBeginGesture),
Pair(DragEndGesture::proximity, ::DragEndGesture)
)
val filtered = candidates.filter { it.first(this, event).abs <= tolerance }
return filtered.minByOrNull { it.first(this, event).abs }?.let { (_, constructor) ->
val gesture = constructor()
gesture.loadFrom(this)
gesture
}
Is there some idioms/reflection/something I could use that would make this easier? In particular the pairs of companion methods to class constructors. I would have rather just enumerated class objects, scoring them on proximity, and then instantiating the best one.