|
|
|
|
|
by lock1
162 days ago
|
|
Well, in a language with nullable reference types, you could use something like fn find<T>(self: List<T>) -> (T, bool)
to express what you want.But exactly like Go's error handling via (fake) unnamed tuple, it's very much error-prone (and return value might contain absurd values like `(someInstanceOfT, false)`). So yeah, I also prefer language w/ ADT which solves it via sum-type rather than being stuck with product-type forever. |
|
I guess if one is always able to construct default values of T then this is not a problem.