3 ms·
The difference is methods. A Result or Option has methods like map that let you transform it regardless of which case it is in, while a null will always crash u
by kazagistar 10y ago
The difference is methods. A Result or Option has methods like map that let you transform it regardless of which case it is in, while a null will always crash unless you match on it first.
- adrusi 10y agoIn that case, do you condsider Go's nil to not be a null, since you can call methods on it that can do whatever? Or how about objective C's nil, where any messages sent to it are simply ignored? Edit: I see now that you're talking about the difference between null and Result/Option, not the difference between null/Option and Unit, so we're talking about different things. Semantically, a value that could be data or null is equivalent to an option type. Option types have methods, yes, but that's just a superficial convenience facility, you could implement the same thing for nullable types by writing a function: public static <A, B> B map(A object, Function<A, B> f) { if (object == null) return null; return f.apply(object); }