I have a bunch of simple functions that take two p...
# functional
j
I have a bunch of simple functions that take two parameters of the same type and return a Boolean (BiPredicates). I want to bind the first parameter to a known value (so now I have a list of Predicates). Next I want to combine different subsets of predicates to filter a structure.
Copy code
fun sameSize(left : Data, right : Data) : Boolean = left.size == right.size
fun equal(left : Data, right : Data) : Boolean = left == right
fun hashMatches(left : Data, right : Data) : Boolean = left.hash == right.hash
fun pHashMatches(left : Data, right : Data)  : Boolean = left.phash == right.phash  

fun partial(data : Data, func : (Data, Data) -> Boolean) : (Data) -> Boolean = {
	func(data, it)
}

val predicates = listOf(
	partial(realised, ::sameSize),
	partial(realised, ::hashMatches)
)

structure.filter{ predicates.fold(true) {acc, func -> func(it) && acc} }
This is what I have so far, how can I improve this? Also, I would ideally traverse the structure only once (admittedly splitting processing across each subset).. not sure how to go about this. I already have arrow in the project so solutions in that are also welcome.