News for hackers. Stuff that matters.
Re:Elegant Error Handling with the JavaScript “Either” Monad by ubertaco on Wednesday June 19, 2019 @04:13PM (#20226886)
A use-case I've had for a quick right-biased Java Either I threw together is handling a migration from java.util.Date to java.time.LocalDate:

    List<LocalDate> dobs = users.stream()
        .map(person -> Either.either(person::getDeprecatedDob, person::getDobLocalDate))
        .map(oldOrNewFormat -> oldOrNewFormat.fold(
            (Date oldFormat) -> convertOldFormatToNew(oldFormat),
            (LocalDate newFormat) -> newFormat,
         ))
        .collect(Collectors.toList());
I use the right-biased-ness of the Either to prefer the new format, if available, but failing that, use the old format and then convert as needed.
Re:Elegant Error Handling with the JavaScript “Either” Monad by james-mcelwain on Wednesday June 19, 2019 @04:33PM (#20227048)
This could be accomplished using Optional#orElseGet without any additional library dependencies, though.
Re:Elegant Error Handling with the JavaScript “Either” Monad by ubertaco on Thursday June 20, 2019 @10:14AM (#20233127)
That's true. I didn't think of doing that. Nice!