I have a `List<Person>` but I want to filter...
# getting-started
c
I have a
List<Person>
but I want to filter out if
Person.socialSecurityNumber
is null. Easy. But what If I want to log each time that filter is hit. Essentially we're trying to be proactive about catching cases where socialSecurityNumber is null because it should "never" be.
Basically have this right now
Copy code
people
    .filter(predicate = { it.social != null }
but in an ideal world, I kinda want is this?
Copy code
people
    .filter(predicate = { it.social != null }, predicateFailedSideEffect = { Sentry.log(it.id) })
s
you could partitionBy and maybe use the scope functions to jerry-rig a call chain that includes logging?
Copy code
val peopleWithSsns = people.partition { it.ssn != null }
  .apply { second.forEach { Sentry.log(it.id) } }
  .first
💯 1
j
it should "never" be
? what about illegal inmigrants?
a
Not knowing the domain and country of OP we have no clue whether or not never really is never. Obligatory US SSN movie btw

https://www.youtube.com/watch?v=Erp8IAUouus

👍 1
👆 1
j
Copy code
people
    .onEach { if (it.social == null) log(...) }
    .filter { it.social != null }
👍 1
💯 1