Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The closest equivalent would be something like:

  Optional<Integer> num = getSomeRiskyNumber();
  return num.map(x -> ...).orElseGet(return error or whatever);
Which is just as type-safe. There are a number of variants, including flatMap for when the map operation itself returns an Optional (the monadic bind operator) and a number of options for how to deal with the empty case.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: