4 ms·
Thanks. I'm just wondering why the example didn't show this extension method. It seems more idiomatic to just call it on the receiver instead of passing a param
by jgavris 4y ago
Thanks. I'm just wondering why the example didn't show this extension method. It seems more idiomatic to just call it on the receiver instead of passing a parameter.
- munificent 4y agoIt's only more idiomatic if you're coming at this from an object-oriented perspective where anything "dispatchy" should be in receiver position. But once you let go of that notion, it's entirely to just have a function that does a type switch.
- jgavris 4y agoI am fine with applying either OO / FP approaches. This example is a sealed class, it is just my opinion that the OO version reads better. And the added benefit of having the function namespaced / bound to the class for IDE support (autocomplete) and documentation.