Class TryStep1<A>

  • Type Parameters:
    A - The type of the first defined value

    public final class TryStep1<A>
    extends java.lang.Object
    The first step of the Try type.

    This class is not intended to be contructed manually, and should only be used as part of a Steps chain, started by Steps.begin(Try)

    Since:
    4.7.0
    See Also:
    for usage examples, Try
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Try<A> try1  
    • Constructor Summary

      Constructors 
      Constructor Description
      TryStep1​(Try<A> try1)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TryStep1<A> filter​(java.util.function.Predicate<? super A> predicate, java.util.function.Supplier<java.lang.Exception> unsatisfiedSupplier)
      Apply the provided predicate with the previous step results.
      <B> TryStep2<A,​B> then​(java.util.function.Function<? super A,​Try<B>> functor)
      Apply the provided function with the previous Step results.
      <B> TryStep2<A,​B> then​(java.util.function.Supplier<Try<B>> supplier)
      Apply the provided supplier with the previous Step results.
      <Z> Try<Z> yield​(java.util.function.Function<? super A,​Z> functor)
      Terminating step expression, that will provide the previous steps to this function and return the result as a Success
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • try1

        private final Try<A> try1
    • Constructor Detail

      • TryStep1

        TryStep1​(Try<A> try1)
    • Method Detail

      • then

        public <B> TryStep2<A,​B> then​(java.util.function.Function<? super A,​Try<B>> functor)
        Apply the provided function with the previous Step results.

        Internally this will perform a Try.flatMap(Function) and the result will become the next step value.

        Type Parameters:
        B - The right hand side type of the next step result
        Parameters:
        functor - The functor to be applied as a flatMap with the previous step
        Returns:
        The next step class
      • then

        public <B> TryStep2<A,​B> then​(java.util.function.Supplier<Try<B>> supplier)
        Apply the provided supplier with the previous Step results.

        Internally this will perform a Try.flatMap(Function) and the supplier will become the next step value.

        This is different to then(Function) in that the previous step results are not provided for the new step evaluation.

        Type Parameters:
        B - The type of the next step result
        Parameters:
        supplier - The supplier to provide the result of the flatMap with the previous step.
        Returns:
        The next step class
      • filter

        public TryStep1<A> filter​(java.util.function.Predicate<? super A> predicate,
                                  java.util.function.Supplier<java.lang.Exception> unsatisfiedSupplier)
        Apply the provided predicate with the previous step results.

        If the predicate is not satisfied then the unsatisfiedSupplier is used to populate the failure value that will prevent any further steps evaluation.

        Parameters:
        predicate - The check that must be satisfied by contained values
        unsatisfiedSupplier - Provide the value to populate the failure if not satisfied
        Returns:
        This step class with either the same last step value, or changed to a failure
      • yield

        public <Z> Try<Z> yield​(java.util.function.Function<? super A,​Z> functor)
        Terminating step expression, that will provide the previous steps to this function and return the result as a Success
        Type Parameters:
        Z - The type for the returned result
        Parameters:
        functor - The yield function to map on previous values
        Returns:
        A Try containing this result as success or failure