Skip to content

Instantly share code, notes, and snippets.

@yogacp
Last active August 17, 2019 18:14
Show Gist options
  • Save yogacp/f8f9fd24c2d017a49c662888324a9f16 to your computer and use it in GitHub Desktop.
Save yogacp/f8f9fd24c2d017a49c662888324a9f16 to your computer and use it in GitHub Desktop.
/**
* High Order Functions
* that execute function only in debug build variant
*/
fun debugMode(function: () -> Unit) {
if (BuildConfig.DEBUG) {
function()
}
}
/**
* How to use the code above
*/
class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
debugMode {
addInterceptor(loggingInterceptor)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment