Skip to content

Instantly share code, notes, and snippets.

@Nilzor
Created March 18, 2020 21:41
Show Gist options
  • Save Nilzor/9656d9b99cfcac1c80cb2d65b4ec7e5e to your computer and use it in GitHub Desktop.
Save Nilzor/9656d9b99cfcac1c80cb2d65b4ec7e5e to your computer and use it in GitHub Desktop.
Kotlin shorthands
fun <R, A, B> withNoNulls(p1: A?, p2: B?, function: (p1: A, p2: B) -> R): R? = p1?.let { p2?.let { function.invoke(p1, p2) } }
fun <R, A, B, C> withNoNulls(p1: A?, p2: B?, p3: C?, function: (p1: A, p2: B, p3: C) -> R): R? = p1?.let { p2?.let { p3?.let { function.invoke(p1, p2, p3) } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment