fooResult = foo(x);
if (fooResult == null) {
return null;
}
barResult = bar(fooResult);
if (barResult == null) {
return null;
}
bazResult = baz(barResult);
if (bazResult == null) {
return null;
}
quuxResult = quux(bazResult);
if (quuxResult == null) {
return null;
}
return quuxResult;
Second, in most cases ignoring errors is not what you want. Knowing which function returned null, and why it returned null, is almost as important as the null itself.Ideally functions would raise an exception instead of returning bad data (aka null) and the psuedo-code snippet above would more cleanly be written:
fooResult = foo(x);
barResult = bar(fooResult);
bazResult = baz(barResult);
return quux(bazResult);
Or to match your single line: return quux(baz(bar(foo)));
The exception would be handled in the same place that handles the eventual Nothing value returned in Haskell.