Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
fun main() {
FakeAppFeatures {
if (SomeFeature.enabled) {
println("some feature is enabled!")
sealed class Feature
object SomeFeature : Feature()
interface AppFeatures {
fun isEnabled(feature: Feature): Boolean
object FakeAppFeatures : AppFeatures {
override fun isEnabled(feature: Feature): Boolean = true
inline class AppFeaturesExtension(val appFeatures: AppFeatures) {
val Feature.enabled: Boolean
get() = appFeatures.isEnabled(this)
val Feature.disabled: Boolean
get() = enabled.not()
inline operator fun <T> AppFeatures.invoke(
appFeaturesExtensionContext: AppFeaturesExtension.() -> T
): T = appFeaturesExtensionContext(AppFeaturesExtension(this))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment