Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Last active September 27, 2023 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KatieBarnett/e9114f458d20e7419ecbaee1e8a624b8 to your computer and use it in GitHub Desktop.
Save KatieBarnett/e9114f458d20e7419ecbaee1e8a624b8 to your computer and use it in GitHub Desktop.
Null Conditional Modifier
inline fun <T> Modifier.nullConditional(
argument: T?,
ifNotNull: Modifier.(T) -> Modifier,
ifNull: Modifier.() -> Modifier = { this },
): Modifier {
return if (argument != null) {
then(ifNotNull(Modifier, argument))
} else {
then(ifNull(Modifier))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment