Hello, World! Hey, I often have functions of the ...
# announcements
b
Hello, World! Hey, I often have functions of the form
fooBar(a: Int? = null, b: String? = null, c: String? = null)
where actually either a, b or c should be non null. Is there an idiomatic way to do this? I think Sealed classes would work, but a bit cumbersome. I've also seen people talking about an Either type (there's one in Arrow). Thoughts?
d
You could either make the sealed class yourself or use the one in Arrow. I recommend just making it yourself. Let the type system work for you.
b
I'm not sure if you're saying I should make my own Either or simply a specific Sealed class for
fooBar
?
d
Specific sealed class.
b
oh ok. I wish there would be an easier way
d
Actually, would a
fooBarA
,
fooBarB
and
fooBarC
make sense?
Each with a single param, of course.
b
hmm 🤔 as an API yes, but internally this will probably duplicate some code. But yeah maybe that would work 🙂 Simple, too!
s
Internally you can keep the original
fooBar
to avoid the duplicated code. You’re still in the same problem as in the beginning, but at least now we can make the problematic method
private
b
sounds good
thanks all 🙂