de.caff.generics.function

## Interface Function0<R>

- Type Parameters:
    `R` - return type
  All Superinterfaces:
    java.util.function.Supplier<R>
  Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

      @FunctionalInterface
      public interface Function0<R>
      extends java.util.function.Supplier<R>

  Function with no parameter. As a pure function this is useless, but there are cases where this is useful like factories.

  The standard Java equivalent is `Supplier`, but this implementation is more extensible. As it is exending `Supplier` it can be used anywhere where a supplier is used.

  Author:
    Rammi
  See Also:
    `Function1`, `Function2`, `Function3`, `Function4`, `Function5`, `Function6`, `Function7`, `Function8`, `Function9`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Function0<java.lang.Object>` | `ALWAYS_NULL` Function which always returns a `null` object.

  - ### Method Summary

    All Methods Static Methods Instance Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> Function0<T>` | `alwaysNull()` Get a zero-argument function which always returns `null`.
    `default <T> Function0<T>` | `andThen(java.util.function.Function<? super R,? extends T> after)` Get a chained function which first applies this function and then the given function to the returned value.
    `default R` | `apply()` Run the function.
    `static <T> Function0<T>` | `from(java.util.function.Supplier<T> supplier)` Make a `Supplier` usable as a `Function0`.
    `default <P1> Function1<R,P1>` | `ignore1()` Make this zero-argument function appear as a function with one ignored argument.
    `static <E extends java.lang.Exception,RR> Function0<RR>` | `nonFragile(FragileFunction0<? extends RR,E> fragileFunction)` Convert a 0-argument function which might throw a checked exception into one which does throw an unchecked exception.
    `static <E extends java.lang.Exception,RR> Function0<RR>` | `nonFragile(FragileFunction0<? extends RR,E> fragileFunction, RR fallback)` Convert a 0-argument function which might throw a checked exception into one which will return a default value instead of throwing an exception.
    `static <E extends java.lang.Exception,RR> Function0<RR>` | `nonFragileX(FragileFunction0<? extends RR,E> fragileFunction, java.util.function.Function<? super E,? extends RR> exceptionHandler)` Convert a 0-argument function which might throw a checked exception into one for which you can decide what happens with the exception.

    - ### Methods inherited from interface java.util.function.Supplier

      `get`

- - ### Field Detail

    - #### ALWAYS_NULL

          @NotNull
          static final Function0<java.lang.Object> ALWAYS_NULL

      Function which always returns a `null` object. Use `alwaysNull()` instead as it handles the return type transparently.

  - ### Method Detail

    - #### apply

          default R apply()

      Run the function.
      Returns:
        return value

    - #### andThen

          @NotNull
          default <T> Function0<T> andThen(@NotNull
                                                    java.util.function.Function<? super R,? extends T> after)

      Get a chained function which first applies this function and then the given function to the returned value.
      Type Parameters:
        `T` - result type of returned function
      Parameters:
        `after` - function to apply after this one
      Returns:
        function chain

    - #### ignore1

          @NotNull
          default <P1> Function1<R,P1> ignore1()

      Make this zero-argument function appear as a function with one ignored argument. This is occasionally useful when a function with an argument is requested, but you want to provide a predefined zero-arg function.
      Type Parameters:
        `P1` - argument type of returned function, ignored
      Returns:
        1-argument function which behaves like this function be ignoring the argument

    - #### alwaysNull

          @NotNull
          static <T> Function0<T> alwaysNull()

      Get a zero-argument function which always returns `null`.
      Type Parameters:
        `T` - result type of returned function
      Returns:
        function always returning `null`

    - #### from

          @NotNull
          static <T> Function0<T> from(@NotNull
                                                java.util.function.Supplier<T> supplier)

      Make a `Supplier` usable as a `Function0`. This is eg useful if you want to use `andThen(Function)`.
      Type Parameters:
        `T` - supplier return type
      Parameters:
        `supplier` - supplier
      Returns:
        `Function0` view of the given supplier

    - #### nonFragile

          @NotNull
          static <E extends java.lang.Exception,RR> Function0<RR> nonFragile(@NotNull
                                                                                      FragileFunction0<? extends RR,E> fragileFunction)

      Convert a 0-argument function which might throw a checked exception into one which does throw an unchecked exception. The returned function will instead throw an unchecked `WrappedFragileException` for any checked exception thrown during `apply()`.
      Type Parameters:
        `E` - exception type
        `RR` - result type of incoming and outgoing function.
      Parameters:
        `fragileFunction` - function throwing a checked exception
      Returns:
        non-fragile function

    - #### nonFragile

          @NotNull
          static <E extends java.lang.Exception,RR> Function0<RR> nonFragile(@NotNull
                                                                                      FragileFunction0<? extends RR,E> fragileFunction,
                                                                                      RR fallback)

      Convert a 0-argument function which might throw a checked exception into one which will return a default value instead of throwing an exception. Please note that the exception is lost in this case.
      Type Parameters:
        `E` - exception type
        `RR` - result type of incoming and outgoing function.
      Parameters:
        `fragileFunction` - function throwing a checked exception
        `fallback` - fallback returned when `fragileFunction` has thrown an exception
      Returns:
        non-fragile function

    - #### nonFragileX

          @NotNull
          static <E extends java.lang.Exception,RR> Function0<RR> nonFragileX(@NotNull
                                                                                       FragileFunction0<? extends RR,E> fragileFunction,
                                                                                       @NotNull
                                                                                       java.util.function.Function<? super E,? extends RR> exceptionHandler)

      Convert a 0-argument function which might throw a checked exception into one for which you can decide what happens with the exception. The exception handler allows
      - throw an unchecked exception instead (compare `nonFragile(FragileFunction0)`)
      - provide a fallback value (compare `nonFragile(FragileFunction0, Object)`)
      - include logging in one of the above
      - and more...
      Type Parameters:
        `E` - exception type
        `RR` - result type of incoming and outgoing function.
      Parameters:
        `fragileFunction` - function throwing a checked exception
        `exceptionHandler` - exception handler. Its return value will be used as return value of the returned function.
      Returns:
        non-fragile function