Davide Giuseppe Farella
07/18/2024, 12:07 PMFoo and Bar, where Bar can be called only using a defined subset of Foo. E.g.
• Foo.A + Bar.A ✅
• Foo.A + Bar.B ✅
• Foo.A + Bar.C ❌
• Foo.B + Bar.A ❌
• Foo.B + Bar.B ❌
• Foo.C + Bar.C ✅
• etc
I do not want to edit Foo (Feature), but I can edit Bar (Interaction)
Something like this 👇 with the difference that Interaction can be bound to multiple types of Feature
Any idea?
// region ### DO NOT EDIT ###
sealed interface Feature {
data object Favorites : Feature
data object Samples : Feature
data object Uploads : Feature
}
// endregion ###
sealed interface Interaction {
data object Filter : Interaction,
CallableFrom<Feature.Samples>
}
sealed interface CallableFrom<F : Feature>
data class ComposedInteraction(val feature: Feature, val interaction: Interaction) : Interaction
infix fun <I, F : Feature> I.from(feature: F) where I : Interaction, I : CallableFrom<F> =
ComposedInteraction(feature, this)
// region ### DO NOT EDIT ###
// Those should compile
Interaction.Filter from Feature.Uploads
Interaction.Filter from Feature.Samples
// This should NOT compile
Interaction.Filter from Feature.Favorites
// endregion ###
To speak, something like
data object Filter : Interaction,
CallableFrom<Feature.Samples>,
CallableFrom<Feature.Uploads>