Skip to content

Commit

Permalink
Merge pull request #94 from everli/feature/modifier-apply-if-not-null
Browse files Browse the repository at this point in the history
[Feature] New ConditionalModifier
  • Loading branch information
GhimpuLucianEduard committed Nov 7, 2023
2 parents a754040 + 0ae66f4 commit a8155cc
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ fun Modifier.applyIf(condition: Boolean, modifier: Modifier): Modifier {
this
}
}

/**
* Apply a [Modifier] if the value to apply is not null
*
* @param value to apply
* @param modifier modifier to be applied
*
* @return [modifier] if the [value] is not null, else [this] without applying [modifier]
*/
fun <T> Modifier.applyIfNotNull(value: T?, modifier: Modifier.(T) -> Modifier): Modifier {
return value?.let { modifier(value) } ?: this
}

0 comments on commit a8155cc

Please sign in to comment.