Been on vacation in South Texas for a couple of weeks, just got back to the AoC2022. Been refactoring my solution framework and puzzling over how to use higher order functions to solve Day 7.
Here's what I ended up with after multiple refactorings (Kotlin):
Here's another way to write the findDirs function in Kotlin, using the also scope function:
Doing it this way, you don't have to create a local variable to collect matches to the given predicate. The also() scope function returns whatever value it was invoked on hence, calling also() on a new instance will return that new instance after the also block is executed.