-
-
Save mushtaq/c83fd4486bdc4a324e422dcc9d761fa7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// comparing to kotlin version: https://proandroiddev.com/extension-classes-f9dcf5878b71 | |
sealed trait Feature | |
object SomeFeature extends Feature | |
trait AppFeatures { | |
def isEnabled(feature: Feature): Boolean | |
} | |
extension (appFeatures: AppFeatures) | |
inline def apply(op: AppFeatures ?=> Unit): Unit = op(using appFeatures) | |
object FakeFeatures extends AppFeatures { | |
def isEnabled(feature: Feature): Boolean = true | |
} | |
extension (feature: Feature)(using appFeatures: AppFeatures) | |
inline def enabled: Boolean = appFeatures.isEnabled(feature) | |
inline def disabled: Boolean = !appFeatures.isEnabled(feature) | |
@main def main() = FakeFeatures { | |
if (SomeFeature.enabled) { | |
println("Some feature is enabled") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment