I have a method as follows:
fun <T1, T2, T3> ifCoordsNotNull(v1: T1?, v2: T2?, v3: T3?, allNotNull: (T1, T2, T3) -> (Unit)) {
if (v1 != null && v2 != null && v3 != null) {
allNotNull(v1, v2, v3)
}
}
I know this is a way to check if multiple values are null; however, it seems to be not too efficient for my needs unless I make several related methods.
Is there a way I could put any/all variables I need to check for null into a list/set, and then recover the results (if any) in a callback with a single method?
To be more specific, I can use the current method like this:
ifCoordsNotNull(loc["x"], loc["y"], loc["z"]) { x, y, z ->
But would prefer, if possible, to create a more ergonomic method that can work in many situations like this:
ifNotNull(linkedSetOf(loc["x"], loc["y"], loc["z"])) { x, y, z ->
If there's anything similar, or a better practice for my needs, please do let me know. Thank you.