// Path: a-foundation/src/main/java/com/ajjpj/afoundation/concurrent/SuccessfulCompletionException.java
// public class SuccessfulCompletionException extends RuntimeException {
//     private final Object originalResult;
// 
//     public SuccessfulCompletionException (Object originalResult) {
//         this.originalResult = originalResult;
//     }
// 
//     /**
//      * @return the 'success' value result
//      */
//     public Object getOriginalResult () {
//         return originalResult;
//     }
// 
//     @Override public synchronized Throwable fillInStackTrace () {
//         return this;
//     }
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/function/AFunction1.java
// public interface AFunction1<P, R, E extends Throwable> extends Serializable {
//     R apply(P param) throws E;
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/function/APartialFunction.java
// public interface APartialFunction<P, R, E extends Throwable> extends AFunction1<P, R, E> {
//     boolean isDefinedAt (P param);
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/function/AStatement1.java
// public interface AStatement1<P, E extends Throwable> extends Serializable {
//     void apply(P param) throws E;
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/util/AUnchecker.java
// public class AUnchecker {
//     public static void throwUnchecked(Throwable th) {
//         AUnchecker.<RuntimeException> doIt(th);
//     }
// 
//     @SuppressWarnings("unchecked")
//     private static <T extends Throwable> void doIt(Throwable th) throws T {
//         throw (T) th;
//     }
// 
//     @SuppressWarnings("unused")
//     public static void executeUnchecked(AStatement0<? extends Throwable> callback) {
//         try {
//             callback.apply();
//         }
//         catch (Throwable exc) {
//             throwUnchecked (exc);
//         }
//     }
// 
//     public static <R> R executeUnchecked(AFunction0<R, ? extends Throwable> callback) {
//         try {
//             return callback.apply();
//         }
//         catch (Throwable exc) {
//             throwUnchecked (exc);
//             return null; //for the compiler
//         }
//     }
// }


import com.ajjpj.afoundation.concurrent.SuccessfulCompletionException;
import com.ajjpj.afoundation.function.AFunction1;
import com.ajjpj.afoundation.function.APartialFunction;
import com.ajjpj.afoundation.function.AStatement1;
import com.ajjpj.afoundation.util.AUnchecker;
package com.ajjpj.afoundation.collection.immutable;



/**
 * An ATry represents either a value ('success') or a Throwable that occurred trying to provide the value ('failure').
 */
public abstract class ATry<T> {
    /**
     * This method creates a successful ATry.
     */
    public static <T> ATry<T> success (T o) {
        return new ASuccess<> (o);
    }

    /**
     * This method creates a failed ATry.
     */
    public static <T> ATry<T> failure (Throwable th) {
        return new AFailure<> (th);
    }

    /**
     * This method executed a statement for the value (in case of success), or does nothing (in case of failure).
     */
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/concurrent/SuccessfulCompletionException.java
// public class SuccessfulCompletionException extends RuntimeException {
//     private final Object originalResult;
// 
//     public SuccessfulCompletionException (Object originalResult) {
//         this.originalResult = originalResult;
//     }
// 
//     /**
//      * @return the 'success' value result
//      */
//     public Object getOriginalResult () {
//         return originalResult;
//     }
// 
//     @Override public synchronized Throwable fillInStackTrace () {
//         return this;
//     }
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/function/AFunction1.java
// public interface AFunction1<P, R, E extends Throwable> extends Serializable {
//     R apply(P param) throws E;
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/function/APartialFunction.java
// public interface APartialFunction<P, R, E extends Throwable> extends AFunction1<P, R, E> {
//     boolean isDefinedAt (P param);
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/function/AStatement1.java
// public interface AStatement1<P, E extends Throwable> extends Serializable {
//     void apply(P param) throws E;
// }
// 
// Path: a-foundation/src/main/java/com/ajjpj/afoundation/util/AUnchecker.java
// public class AUnchecker {
//     public static void throwUnchecked(Throwable th) {
//         AUnchecker.<RuntimeException> doIt(th);
//     }
// 
//     @SuppressWarnings("unchecked")
//     private static <T extends Throwable> void doIt(Throwable th) throws T {
//         throw (T) th;
//     }
// 
//     @SuppressWarnings("unused")
//     public static void executeUnchecked(AStatement0<? extends Throwable> callback) {
//         try {
//             callback.apply();
//         }
//         catch (Throwable exc) {
//             throwUnchecked (exc);
//         }
//     }
// 
//     public static <R> R executeUnchecked(AFunction0<R, ? extends Throwable> callback) {
//         try {
//             return callback.apply();
//         }
//         catch (Throwable exc) {
//             throwUnchecked (exc);
//             return null; //for the compiler
//         }
//     }
// }


// Path: a-foundation/src/main/java/com/ajjpj/afoundation/collection/immutable/ATry.java
import com.ajjpj.afoundation.concurrent.SuccessfulCompletionException;
import com.ajjpj.afoundation.function.AFunction1;
import com.ajjpj.afoundation.function.APartialFunction;
import com.ajjpj.afoundation.function.AStatement1;
import com.ajjpj.afoundation.util.AUnchecker;

package com.ajjpj.afoundation.collection.immutable;



/**
 * An ATry represents either a value ('success') or a Throwable that occurred trying to provide the value ('failure').
 */
public abstract class ATry<T> {
    /**
     * This method creates a successful ATry.
     */
    public static <T> ATry<T> success (T o) {
        return new ASuccess<> (o);
    }

    /**
     * This method creates a failed ATry.
     */
    public static <T> ATry<T> failure (Throwable th) {
        return new AFailure<> (th);
    }

    /**
     * This method executed a statement for the value (in case of success), or does nothing (in case of failure).
     */
    public abstract <X extends Throwable> void foreach (AStatement1<T, X> f) throws X;