Say I have: ```sealed interface Foo sealed interf...
# arrow
d
Say I have:
Copy code
sealed interface Foo

sealed interface FooForBar : Foo {
  val bar: Bar
}

@JvmInline
value class Bar(val value: String) {
  companion object {
    val EMPTY = Bar("")
  }
}
And I need to manage a list of Foos that don't derive from ForForBar and a
Map<Bar, ForForBar>
is it a bad practice to keep them both in one map and to use
Bar.EMPTY
as the key for the ones deriving only from Foo?
c
The example you provided is very abstract, it's difficult to decide if it's a good idea or not based on just this. Maybe for some cases it may make sense, maybe for some others it won't.
d
I use this in a few contexts... in this case Foo is a general action that acts more globally, whereas FooForBar is one that only acts for a particular object where Bar is it's Id.
Now that I think of it... you're right, it could be that if it would just be a simple model, I could have done it that way... and in other contexts that I use this pattern, it really is... But first, there could be multiple Actions without a Bar... and second, those actions should only have one of each type... I wonder if I'd have to override the equals on each of those to get a Set of unique types whether their properties are the same or not... Is it better to create a data class with all the types of Foo nullable and to save it instead of a Set?
It's a bit hard to start thinking in the "functional" modelling style... but I like it 😊...
u
What is an action in your context? Is it pure data, or something that can be executed; i.e., a function reference?
d
Pure data being sent by an API