Sternbach-Software / GeniForAndroid

Geni.com Android app
GNU General Public License v3.0
3 stars 1 forks source link

Algorithm for filtering tree search results by whether they are related #6

Open Sternbach-Software opened 1 year ago

Sternbach-Software commented 1 year ago

Use KotlinFunctionLibrary.recursiveMap

fun PersonNode.getSurroundingPeople(includeSpouseFamily: Boolean = true) = origin.parents + origin.siblings + origin.children + (if(includeSpouseFamily) listOf(origin.spouse) else listOf())
origin.getSurroundingPeople().recursiveMapNotNull({ it.getSurroundingPeople()) { if(it.matchesConstraint(...)) it else null }

If I'm not mistaken, this will use depth first search starting with the parents.