// Path: mug/src/main/java/com/google/mu/function/CheckedBiFunction.java
// @FunctionalInterface
// public interface CheckedBiFunction<A, B, T, E extends Throwable> {
//   T apply(A a, B b) throws E;
// 
//   /**
//    * Returns a new {@code CheckedBiFunction} that maps the return value using {@code mapper}.
//    * For example: {@code ((a, b) -> a + b).andThen(Object::toString).apply(1, 2) => "3"}.
//    */
//   default <R> CheckedBiFunction<A, B, R, E> andThen(
//       CheckedFunction<? super T, ? extends R, ? extends E> mapper) {
//     requireNonNull(mapper);
//     return (a, b) -> mapper.apply(apply(a, b));
//   }
// }
// 
// Path: mug/src/main/java/com/google/mu/function/CheckedConsumer.java
// @FunctionalInterface
// public interface CheckedConsumer<T, E extends Throwable> {
//   void accept(T input) throws E;
// 
//   /**
//    * Returns a new {@code CheckedConsumer} that also passes the input to {@code that}.
//    * For example: {@code out::writeObject.andThen(logger::info).accept("message")}.
//    */
//   default CheckedConsumer<T, E> andThen(CheckedConsumer<? super T, E> that) {
//     requireNonNull(that);
//     return input -> {
//       accept(input);
//       that.accept(input);
//     };
//   }
// }
// 
// Path: mug/src/main/java/com/google/mu/function/CheckedFunction.java
// @FunctionalInterface
// public interface CheckedFunction<F, T, E extends Throwable> {
//   T apply(F from) throws E;
// 
//   /**
//    * Returns a new {@code CheckedFunction} that maps the return value using {@code mapper}.
//    * For example: {@code (x -> x).andThen(Object::toString).apply(1) => "1"}.
//    */
//   default <R> CheckedFunction<F, R, E> andThen(
//       CheckedFunction<? super T, ? extends R, ? extends E> mapper) {
//     requireNonNull(mapper);
//     return f -> mapper.apply(apply(f));
//   }
// }
// 
// Path: mug/src/main/java/com/google/mu/function/CheckedSupplier.java
// @FunctionalInterface
// public interface CheckedSupplier<T, E extends Throwable> {
//   T get() throws E;
// 
//   /**
//    * Returns a new {@code CheckedSupplier} that maps the return value using {@code mapper}.
//    * For example: {@code (x -> 1).andThen(Object::toString).get() => "1"}.
//    */
//   default <R> CheckedSupplier<R, E> andThen(
//       CheckedFunction<? super T, ? extends R, ? extends E> mapper) {
//     requireNonNull(mapper);
//     return () -> mapper.apply(get());
//   }
// }


import com.google.mu.function.CheckedConsumer;
import com.google.mu.function.CheckedFunction;
import com.google.mu.function.CheckedSupplier;
import static java.util.Objects.requireNonNull;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import com.google.mu.function.CheckedBiFunction;
   * {@code Stream}. This is specially useful in a {@link Stream} chain to handle and then ignore
   * exceptional results.
   */
  public final <X extends Throwable> Stream<T> catching(
      CheckedConsumer<? super E, ? extends X> handler) throws X {
    requireNonNull(handler);
    return map(Stream::of).orElse(e -> {
      handler.accept(e);
      return Stream.empty();
    });
  }

  /**
   * Turns {@code condition} to a {@code Predicate} over {@code Maybe}. The returned predicate
   * matches any {@code Maybe} with a matching value, as well as any exceptional {@code Maybe} so
   * as not to accidentally swallow exceptions.
   */
  public static <T, E extends Throwable> Predicate<Maybe<T, E>> byValue(
      Predicate<? super T> condition) {
    requireNonNull(condition);
    return maybe -> maybe.map(condition::test).orElse(e -> true);
  }

  /**
   * Invokes {@code supplier} and wraps the returned object or thrown exception in a
   * {@code Maybe<T, E>}.
   *
   * <p>Unchecked exceptions will be immediately propagated without being wrapped.
   */
  public static <T, E extends Throwable> Maybe<T, E> maybe(
// Path: mug/src/main/java/com/google/mu/function/CheckedBiFunction.java
// @FunctionalInterface
// public interface CheckedBiFunction<A, B, T, E extends Throwable> {
//   T apply(A a, B b) throws E;
// 
//   /**
//    * Returns a new {@code CheckedBiFunction} that maps the return value using {@code mapper}.
//    * For example: {@code ((a, b) -> a + b).andThen(Object::toString).apply(1, 2) => "3"}.
//    */
//   default <R> CheckedBiFunction<A, B, R, E> andThen(
//       CheckedFunction<? super T, ? extends R, ? extends E> mapper) {
//     requireNonNull(mapper);
//     return (a, b) -> mapper.apply(apply(a, b));
//   }
// }
// 
// Path: mug/src/main/java/com/google/mu/function/CheckedConsumer.java
// @FunctionalInterface
// public interface CheckedConsumer<T, E extends Throwable> {
//   void accept(T input) throws E;
// 
//   /**
//    * Returns a new {@code CheckedConsumer} that also passes the input to {@code that}.
//    * For example: {@code out::writeObject.andThen(logger::info).accept("message")}.
//    */
//   default CheckedConsumer<T, E> andThen(CheckedConsumer<? super T, E> that) {
//     requireNonNull(that);
//     return input -> {
//       accept(input);
//       that.accept(input);
//     };
//   }
// }
// 
// Path: mug/src/main/java/com/google/mu/function/CheckedFunction.java
// @FunctionalInterface
// public interface CheckedFunction<F, T, E extends Throwable> {
//   T apply(F from) throws E;
// 
//   /**
//    * Returns a new {@code CheckedFunction} that maps the return value using {@code mapper}.
//    * For example: {@code (x -> x).andThen(Object::toString).apply(1) => "1"}.
//    */
//   default <R> CheckedFunction<F, R, E> andThen(
//       CheckedFunction<? super T, ? extends R, ? extends E> mapper) {
//     requireNonNull(mapper);
//     return f -> mapper.apply(apply(f));
//   }
// }
// 
// Path: mug/src/main/java/com/google/mu/function/CheckedSupplier.java
// @FunctionalInterface
// public interface CheckedSupplier<T, E extends Throwable> {
//   T get() throws E;
// 
//   /**
//    * Returns a new {@code CheckedSupplier} that maps the return value using {@code mapper}.
//    * For example: {@code (x -> 1).andThen(Object::toString).get() => "1"}.
//    */
//   default <R> CheckedSupplier<R, E> andThen(
//       CheckedFunction<? super T, ? extends R, ? extends E> mapper) {
//     requireNonNull(mapper);
//     return () -> mapper.apply(get());
//   }
// }


// Path: mug/src/main/java/com/google/mu/util/Maybe.java
import com.google.mu.function.CheckedConsumer;
import com.google.mu.function.CheckedFunction;
import com.google.mu.function.CheckedSupplier;
import static java.util.Objects.requireNonNull;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import com.google.mu.function.CheckedBiFunction;

   * {@code Stream}. This is specially useful in a {@link Stream} chain to handle and then ignore
   * exceptional results.
   */
  public final <X extends Throwable> Stream<T> catching(
      CheckedConsumer<? super E, ? extends X> handler) throws X {
    requireNonNull(handler);
    return map(Stream::of).orElse(e -> {
      handler.accept(e);
      return Stream.empty();
    });
  }

  /**
   * Turns {@code condition} to a {@code Predicate} over {@code Maybe}. The returned predicate
   * matches any {@code Maybe} with a matching value, as well as any exceptional {@code Maybe} so
   * as not to accidentally swallow exceptions.
   */
  public static <T, E extends Throwable> Predicate<Maybe<T, E>> byValue(
      Predicate<? super T> condition) {
    requireNonNull(condition);
    return maybe -> maybe.map(condition::test).orElse(e -> true);
  }

  /**
   * Invokes {@code supplier} and wraps the returned object or thrown exception in a
   * {@code Maybe<T, E>}.
   *
   * <p>Unchecked exceptions will be immediately propagated without being wrapped.
   */
  public static <T, E extends Throwable> Maybe<T, E> maybe(
      CheckedSupplier<? extends T, ? extends E> supplier) {