yegor256 / cactoos

Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons
https://www.cactoos.org
MIT License
737 stars 163 forks source link

(#1572) Covariance for `func.FuncWithFallback` #1607

Closed DmitryBarskov closed 3 years ago

DmitryBarskov commented 3 years ago

For #1572:

Now fallbacks for ScalarWithFallback and FuncWithFallback can produce object derived types from given original type.

Fallback<Long> longOnNoFile = new Fallback.From<>(FileNotFoundException.class, _t -> 0L);
Fallback<Double> doubleOnIo = new Fallback.From<>(IOException.class, _t -> 0.0);
Fallback<Integer> intOtherwise = new Fallback.From<>(Exception.class, _t -> 0);

Func<String, Number> readFileLength = new FuncOf<>(fileName -> {
  throw new IOException("Access denied. You can't read file " + fileName);
});

FuncWithFallback<String, Number> safeReadFileLength =
  new FuncWithFallback<String, Number>(
    readFileLength,
    longOnNoFile,
    doubleOnIo,
    intOtherwise
  );
victornoel commented 3 years ago

@rultor merge

rultor commented 3 years ago

@rultor merge

@victornoel OK, I'll try to merge now. You can check the progress of the merge here

rultor commented 3 years ago

@rultor merge

@victornoel Done! FYI, the full log is here (took me 8min)

victornoel commented 3 years ago

@0crat status

0crat commented 3 years ago

@andreoss/z resigned from #1607, since the job is not in scope anymore