// Path: src/main/java/org/smallibs/suitcase/cases/Case.java
// interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> {
//     static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) {
//         return aCase::unapply;
//     }
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java
// interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> {
//     static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) {
//         return aCase::unapply;
//     }
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/Result.java
// public abstract class Result<R> {
// 
//     public static <R> WithoutCapture<R> success(R term) {
//         return new WithoutCapture<>(term);
//     }
// 
//     public static <C> WithCapture<C> successWithCapture(C result) {
//         return new WithCapture<>(result);
//     }
// 
//     private final R capturedObject;
// 
//     public Result(R capturedObject) {
//         this.capturedObject = capturedObject;
//     }
// 
//     public R resultValue() {
//         return capturedObject;
//     }
// 
//     public static class WithCapture<C> extends Result<C> {
//         public WithCapture(C capturedObject) {
//             super(capturedObject);
//         }
//     }
// 
//     public static class WithoutCapture<T> extends Result<T> {
//         public WithoutCapture(T capturedObject) {
//             super(capturedObject);
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java
// public class Pair<T1, T2> {
// 
//     public final T1 _1;
//     public final T2 _2;
// 
//     public Pair(T1 _1, T2 _2) {
//         this._1 = _1;
//         this._2 = _2;
//     }
// }


import org.smallibs.suitcase.cases.Case.WithCapture;
import org.smallibs.suitcase.cases.Case.WithoutCapture;
import org.smallibs.suitcase.cases.Result;
import org.smallibs.suitcase.utils.Pair;
import java.util.Optional;
import java.util.function.Function;
/*
 *
 *  * Copyright (C)3024 D. Plaindoux.
 *  *
 *  * This program is free software; you can redistribute it and/or modify it
 *  * under the terms of the GNU Lesser General Public License as published
 *  * by the Free Software Foundation; either version 3, or (at your option) any
 *  * later version.
 *  *
 *  * This program is distributed in the hope that it will be useful,
 *  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  * GNU Lesser General Public License for more details.
 *  *
 *  * You should have received a copy of the GNU Lesser General Public License
 *  * along with this program; see the file COPYING.  If not, write to
 *  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA.
 *  
 */

package org.smallibs.suitcase.cases.core;



;

public class Case5<P, R, E1, E2, E3, E4, E5> {

    private final Function<P, Optional<R>> predicate;
    private final Function<P, E1> compute1;
    private final Function<P, E2> compute2;
    private final Function<P, E3> compute3;
    private final Function<P, E4> compute4;
    private final Function<P, E5> compute5;

    public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) {
        this.predicate = predicate;
        this.compute1 = compute1;
        this.compute2 = compute2;
        this.compute3 = compute3;
        this.compute4 = compute4;
        this.compute5 = compute5;
    }

    public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) {
        final Case4<P, R, E1, E2, E3, Pair<E4, E5>> case4 =
                new Case4<>(predicate, compute1, compute2, compute3, (p -> new Pair<>(compute4.apply(p), compute5.apply(p))));

        final WithoutCapture<Pair<E4, E5>, Pair<C4, C5>> capture = e4e5 ->
                aCase4.unapply(e4e5._1)
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java
// interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> {
//     static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) {
//         return aCase::unapply;
//     }
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java
// interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> {
//     static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) {
//         return aCase::unapply;
//     }
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/Result.java
// public abstract class Result<R> {
// 
//     public static <R> WithoutCapture<R> success(R term) {
//         return new WithoutCapture<>(term);
//     }
// 
//     public static <C> WithCapture<C> successWithCapture(C result) {
//         return new WithCapture<>(result);
//     }
// 
//     private final R capturedObject;
// 
//     public Result(R capturedObject) {
//         this.capturedObject = capturedObject;
//     }
// 
//     public R resultValue() {
//         return capturedObject;
//     }
// 
//     public static class WithCapture<C> extends Result<C> {
//         public WithCapture(C capturedObject) {
//             super(capturedObject);
//         }
//     }
// 
//     public static class WithoutCapture<T> extends Result<T> {
//         public WithoutCapture(T capturedObject) {
//             super(capturedObject);
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java
// public class Pair<T1, T2> {
// 
//     public final T1 _1;
//     public final T2 _2;
// 
//     public Pair(T1 _1, T2 _2) {
//         this._1 = _1;
//         this._2 = _2;
//     }
// }


// Path: src/main/java/org/smallibs/suitcase/cases/core/Case5.java
import org.smallibs.suitcase.cases.Case.WithCapture;
import org.smallibs.suitcase.cases.Case.WithoutCapture;
import org.smallibs.suitcase.cases.Result;
import org.smallibs.suitcase.utils.Pair;
import java.util.Optional;
import java.util.function.Function;

/*
 *
 *  * Copyright (C)3024 D. Plaindoux.
 *  *
 *  * This program is free software; you can redistribute it and/or modify it
 *  * under the terms of the GNU Lesser General Public License as published
 *  * by the Free Software Foundation; either version 3, or (at your option) any
 *  * later version.
 *  *
 *  * This program is distributed in the hope that it will be useful,
 *  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  * GNU Lesser General Public License for more details.
 *  *
 *  * You should have received a copy of the GNU Lesser General Public License
 *  * along with this program; see the file COPYING.  If not, write to
 *  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA.
 *  
 */

package org.smallibs.suitcase.cases.core;



;

public class Case5<P, R, E1, E2, E3, E4, E5> {

    private final Function<P, Optional<R>> predicate;
    private final Function<P, E1> compute1;
    private final Function<P, E2> compute2;
    private final Function<P, E3> compute3;
    private final Function<P, E4> compute4;
    private final Function<P, E5> compute5;

    public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) {
        this.predicate = predicate;
        this.compute1 = compute1;
        this.compute2 = compute2;
        this.compute3 = compute3;
        this.compute4 = compute4;
        this.compute5 = compute5;
    }

    public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) {
        final Case4<P, R, E1, E2, E3, Pair<E4, E5>> case4 =
                new Case4<>(predicate, compute1, compute2, compute3, (p -> new Pair<>(compute4.apply(p), compute5.apply(p))));

        final WithoutCapture<Pair<E4, E5>, Pair<C4, C5>> capture = e4e5 ->
                aCase4.unapply(e4e5._1)
                        .flatMap(c4 -> aCase5.unapply(e4e5._2).map(c5 -> Result.success(new Pair<>(c4.resultValue(), c5.resultValue()))));