Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. private static <T1, T2, T3> ForSupplier3Option<T1, T2, T3> For(Supplier<Option<T1>> ts1,
  2. Supplier<Option<T2>> ts2,
  3. Supplier<Option<T3>> ts3) {
  4.  return new ForSupplier3Option<>(ts1, ts2, ts3);
  5. }
  6.  
  7. public static class ForSupplier3Option<T1, T2, T3> {
  8. private final Supplier<Option<T1>> ts1;
  9.   private final Supplier<Option<T2>> ts2;
  10.   private final Supplier<Option<T3>> ts3;
  11.  
  12. private ForSupplier3Option(Supplier<Option<T1>> ts1, Supplier<Option<T2>> ts2, Supplier<Option<T3>> ts3) {
  13. this.ts1 = ts1;
  14.  this.ts2 = ts2;
  15.  this.ts3 = ts3;
  16.   }
  17.  
  18.   public <R> Option<R> yield(Function3<? super T1, ? super T2, ? super T3, ? extends R> f) {
  19.   Objects.requireNonNull(f, "f is null");
  20.   return
  21.   ts1.get().flatMap(t1 ->
  22.   ts2.get().flatMap(t2 ->
  23.   ts3.get().map(t3 -> f.apply(t1, t2, t3))));
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement