xii
08/25/2020, 11:58 AMxii
08/25/2020, 11:58 AMxii
08/25/2020, 12:01 PMprivate inline fun Iterable<TestObject>.emptyFilterIfNotContained(predicate: (TestObject) -> TestObject): List<TestObject>{
return filterTo(ArrayList(), predicate).ifEmpty{ filterTo(ArrayList(), {it.b.isEmpty()}
}
but I want b to be variable, as in, be the object that the predicate just compared toxii
08/25/2020, 12:02 PMtest.emptyFilterIfNotContained { it.b.contains('a')}
then it should check for b,
but if I sent it.a.contains in the predicate, it should do it.a.isEmpty()Vlad
08/25/2020, 12:31 PMprivate inline fun Iterable<TestObject>.emptyFilterIfNotContained(getValue:(TestObject)-> String, predicate: (String) -> Boolean): List<TestObject>{
return filterTo(ArrayList()){predicate(getValue(it))}.ifEmpty { filterTo(ArrayList(), { getValue(it).isEmpty() })}
}
and use like this
test.emptyFilterIfNotContained({it.a},{it.contains('a')})
xii
08/25/2020, 12:44 PMxii
08/25/2020, 12:44 PMMarc Knaup
08/25/2020, 7:00 PMfilterTo?