View Javadoc
1   package io.atlassian.fugue.extensions.step;
2   
3   import io.atlassian.fugue.Option;
4   import io.atlassian.fugue.extensions.functions.Function6;
5   import io.atlassian.fugue.extensions.functions.Predicate6;
6   
7   /**
8    * The sixth step of the {@link Option} type.
9    * <p>
10   * This class is not intended to be contructed manually, and should only be used
11   * as part of a {@link Steps} chain, started by {@link Steps#begin(Option)}
12   *
13   * @param <A> The type of the first defined value
14   * @param <B> The type of the second defined value
15   * @param <C> The type of the third defined value
16   * @param <D> The type of the fourth defined value
17   * @param <E> The type of the fifth defined value
18   * @param <F> The type of the sixth defined value
19   * @see Steps for usage examples
20   * @see Option
21   * @since 4.7.0
22   */
23  public final class OptionStep6<A, B, C, D, E, F> {
24    private final Option<A> option1;
25    private final Option<B> option2;
26    private final Option<C> option3;
27    private final Option<D> option4;
28    private final Option<E> option5;
29    private final Option<F> option6;
30  
31    OptionStep6(Option<A> option1, Option<B> option2, Option<C> option3, Option<D> option4, Option<E> option5, Option<F> option6) {
32      this.option1 = option1;
33      this.option2 = option2;
34      this.option3 = option3;
35      this.option4 = option4;
36      this.option5 = option5;
37      this.option6 = option6;
38    }
39  
40    /**
41     * Apply the provided predicate with the previous step results.
42     *
43     * @param predicate The check that must be satisfied by contained values
44     * @return This step class with either the same last step value, or changed to
45     * none
46     */
47    public OptionStep6<A, B, C, D, E, F> filter(Predicate6<? super A, ? super B, ? super C, ? super D, ? super E, ? super F> predicate) {
48      Option<F> filterOption6 = option1.flatMap(value1 -> option2.flatMap(value2 -> option3.flatMap(value3 -> option4.flatMap(value4 -> option5
49        .flatMap(value5 -> option6.filter(value6 -> predicate.test(value1, value2, value3, value4, value5, value6)))))));
50      return new OptionStep6<>(option1, option2, option3, option4, option5, filterOption6);
51    }
52  
53    /**
54     * Terminating step expression, that will provide the previous steps to this
55     * function and return the result as a <code>some</code>
56     *
57     * @param functor The yield function to map on previous values
58     * @param <Z> The type for the returned result
59     * @return An Option containing this result or none
60     */
61    public <Z> Option<Z> yield(Function6<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, Z> functor) {
62      return option1.flatMap(value1 -> option2.flatMap(value2 -> option3.flatMap(value3 -> option4.flatMap(value4 -> option5.flatMap(value5 -> option6
63        .map(value6 -> functor.apply(value1, value2, value3, value4, value5, value6)))))));
64    }
65  }