Skip to content

Instantly share code, notes, and snippets.

@GiorgioNatili
Last active March 5, 2018 06:56
Show Gist options
  • Save GiorgioNatili/67d722b043064a510caffb0772cf949a to your computer and use it in GitHub Desktop.
Save GiorgioNatili/67d722b043064a510caffb0772cf949a to your computer and use it in GitHub Desktop.
Run a lambda only when the objects don't contain a null property
package io.a2xe.experiments.selfielifecycle.utilities
/**
* Created by giorgio on 3/4/18.
*/
fun <T:Any> whenNotNullObjects(vararg args: T?, action: () -> Unit) {
args.forEach {target ->
checkNotNull(target) {
target!!::class.java.declaredFields.forEach {
if(it.get(target) == null) {
return
}
}
}
}
action()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment