@file:JvmName("KomprehensionsPromise")

package ir.iais.utilities.javautils.utils

import ir.iais.utilities.javautils.commonForkJoinPool
import java.util.concurrent.CompletionStage
import java.util.concurrent.Executor

fun <T, R> CompletionStage<T>.flatMap(executor: Executor = commonForkJoinPool, func: (T) -> CompletionStage<R>): CompletionStage<R> =
        this.thenComposeAsync(java.util.function.Function { func(it) }, executor)

fun <T, R> CompletionStage<T>.map(executor: Executor = commonForkJoinPool, func: (T) -> R): CompletionStage<R> =
        this.thenApplyAsync(java.util.function.Function { func(it) }, executor)

/**
 * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
 *
 * @return composed Observable
 */
fun <A, R> doFlatMap(
        zero: () -> CompletionStage<A>,
        one: (A) -> CompletionStage<R>): CompletionStage<R> =
        zero.invoke()
                .flatMap { a ->
                    one.invoke(a)
                }

///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                                        .flatMap { c ->
//                                            three.invoke(a, b, c)
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                                        .flatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .flatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                                        .flatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .flatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .flatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                                        .flatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .flatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .flatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .flatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                                        .flatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .flatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .flatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .flatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .flatMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<H>,
//        eight: (A, B, C, D, E, F, G, H) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                                        .flatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .flatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .flatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .flatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .flatMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                                    .flatMap { h ->
//                                                                                                        eight.invoke(a, b, c, d, e, f, g, h)
//                                                                                                    }
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.flatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, I, R> doFlatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<H>,
//        eight: (A, B, C, D, E, F, G, H) -> CompletionStage<I>,
//        nine: (A, B, C, D, E, F, G, H, I) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .flatMap { a ->
//                    one.invoke(a)
//                            .flatMap { b ->
//                                two.invoke(a, b)
//                                        .flatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .flatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .flatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .flatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .flatMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                                    .flatMap { h ->
//                                                                                                        eight.invoke(a, b, c, d, e, f, g, h)
//                                                                                                                .flatMap { i ->
//                                                                                                                    nine.invoke(a, b, c, d, e, f, g, h, i)
//                                                                                                                }
//                                                                                                    }
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                                        .concatMap { c ->
//                                            three.invoke(a, b, c)
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                                        .concatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .concatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                                        .concatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .concatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .concatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                                        .concatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .concatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .concatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .concatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                                        .concatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .concatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .concatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .concatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .concatMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<H>,
//        eight: (A, B, C, D, E, F, G, H) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                                        .concatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .concatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .concatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .concatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .concatMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                                    .concatMap { h ->
//                                                                                                        eight.invoke(a, b, c, d, e, f, g, h)
//                                                                                                    }
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.concatMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, I, R> doConcatMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<H>,
//        eight: (A, B, C, D, E, F, G, H) -> CompletionStage<I>,
//        nine: (A, B, C, D, E, F, G, H, I) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .concatMap { a ->
//                    one.invoke(a)
//                            .concatMap { b ->
//                                two.invoke(a, b)
//                                        .concatMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .concatMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .concatMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .concatMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .concatMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                                    .concatMap { h ->
//                                                                                                        eight.invoke(a, b, c, d, e, f, g, h)
//                                                                                                                .concatMap { i ->
//                                                                                                                    nine.invoke(a, b, c, d, e, f, g, h, i)
//                                                                                                                }
//                                                                                                    }
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                                        .switchMap { c ->
//                                            three.invoke(a, b, c)
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                                        .switchMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .switchMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                                        .switchMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .switchMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .switchMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                                        .switchMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .switchMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .switchMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .switchMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                                        .switchMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .switchMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .switchMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .switchMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .switchMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<H>,
//        eight: (A, B, C, D, E, F, G, H) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                                        .switchMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .switchMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .switchMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .switchMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .switchMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                                    .switchMap { h ->
//                                                                                                        eight.invoke(a, b, c, d, e, f, g, h)
//                                                                                                    }
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple creation functions chained by [rx.Observable.switchMap].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, I, R> doSwitchMap(
//        zero: () -> CompletionStage<A>,
//        one: (A) -> CompletionStage<B>,
//        two: (A, B) -> CompletionStage<C>,
//        three: (A, B, C) -> CompletionStage<D>,
//        four: (A, B, C, D) -> CompletionStage<E>,
//        five: (A, B, C, D, E) -> CompletionStage<F>,
//        six: (A, B, C, D, E, F) -> CompletionStage<G>,
//        seven: (A, B, C, D, E, F, G) -> CompletionStage<H>,
//        eight: (A, B, C, D, E, F, G, H) -> CompletionStage<I>,
//        nine: (A, B, C, D, E, F, G, H, I) -> CompletionStage<R>): CompletionStage<R> =
//        zero.invoke()
//                .switchMap { a ->
//                    one.invoke(a)
//                            .switchMap { b ->
//                                two.invoke(a, b)
//                                        .switchMap { c ->
//                                            three.invoke(a, b, c)
//                                                    .switchMap { d ->
//                                                        four.invoke(a, b, c, d)
//                                                                .switchMap { e ->
//                                                                    five.invoke(a, b, c, d, e)
//                                                                            .switchMap { f ->
//                                                                                six.invoke(a, b, c, d, e, f)
//                                                                                        .switchMap { g ->
//                                                                                            seven.invoke(a, b, c, d, e, f, g)
//                                                                                                    .switchMap { h ->
//                                                                                                        eight.invoke(a, b, c, d, e, f, g, h)
//                                                                                                                .switchMap { i ->
//                                                                                                                    nine.invoke(a, b, c, d, e, f, g, h, i)
//                                                                                                                }
//                                                                                                    }
//                                                                                        }
//                                                                            }
//                                                                }
//                                                    }
//                                        }
//                            }
//                }
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, C, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, C>,
//        three: ObservableTransformer<C, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//                .compose(three)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, C>,
//        three: ObservableTransformer<C, D>,
//        four: ObservableTransformer<D, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//                .compose(three)
//                .compose(four)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, C>,
//        three: ObservableTransformer<C, D>,
//        four: ObservableTransformer<D, E>,
//        five: ObservableTransformer<E, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//                .compose(three)
//                .compose(four)
//                .compose(five)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, C>,
//        three: ObservableTransformer<C, D>,
//        four: ObservableTransformer<D, E>,
//        five: ObservableTransformer<E, F>,
//        six: ObservableTransformer<F, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//                .compose(three)
//                .compose(four)
//                .compose(five)
//                .compose(six)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, C>,
//        three: ObservableTransformer<C, D>,
//        four: ObservableTransformer<D, E>,
//        five: ObservableTransformer<E, F>,
//        six: ObservableTransformer<F, G>,
//        seven: ObservableTransformer<G, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//                .compose(three)
//                .compose(four)
//                .compose(five)
//                .compose(six)
//                .compose(seven)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, C>,
//        three: ObservableTransformer<C, D>,
//        four: ObservableTransformer<D, E>,
//        five: ObservableTransformer<E, F>,
//        six: ObservableTransformer<F, G>,
//        seven: ObservableTransformer<G, H>,
//        eight: ObservableTransformer<H, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//                .compose(three)
//                .compose(four)
//                .compose(five)
//                .compose(six)
//                .compose(seven)
//                .compose(eight)
//
///**
// * Composes an [rx.Observable] from multiple [Transformer] chained by [Observable.compose].
// *
// * @return composed Observable
// */
//fun <A, B, C, D, E, F, G, H, I, R> doCompose(
//        zero: () -> CompletionStage<A>,
//        one: ObservableTransformer<A, B>,
//        two: ObservableTransformer<B, C>,
//        three: ObservableTransformer<C, D>,
//        four: ObservableTransformer<D, E>,
//        five: ObservableTransformer<E, F>,
//        six: ObservableTransformer<F, G>,
//        seven: ObservableTransformer<G, H>,
//        eight: ObservableTransformer<H, I>,
//        nine: ObservableTransformer<I, R>): CompletionStage<R> =
//        zero()
//                .compose(one)
//                .compose(two)
//                .compose(three)
//                .compose(four)
//                .compose(five)
//                .compose(six)
//                .compose(seven)
//                .compose(eight)
//                .compose(nine)
