Implement reduceOpt and use it for reduce with exception