Package jsonvalues

Interface Trampoline<T>

  • Type Parameters:
    T - the type of the result
    All Superinterfaces:
    Supplier<T>

    public interface Trampoline<T>
    extends Supplier<T>
    Trampolines allow to define recursive algorithms by iterative loops without blowing the stack when methods implementations are tail recursive.
    • Method Detail

      • map

        default <R> Trampoline<R> map​(Function<? super T,​? extends R> fn)
        maps this trampoline which returns a T, into another one that returns a R. When the method get() is invoked, this trampoline is executed and then the result is mapped.
        Type Parameters:
        R - type of the result
        Parameters:
        fn - the map function, from T to R
        Returns:
        a Trampoline of type R
      • flatMap

        default <R> Trampoline<R> flatMap​(Function<? super T,​? extends Trampoline<R>> fn)
        map this trampoline which returns a T, into another one that returns a R. When the method get() is invoked, this trampoline is executed and then the result of type T is passed to the trampoline specified in the flatMap function, which will return a R. So, two trampolines are executed, one after the other.
        Type Parameters:
        R - type of the result
        Parameters:
        fn - the map function, from T to Trampoline<R>
        Returns:
        a Trampoline of type R
      • bounce

        default Trampoline<T> bounce()
        Returns:
        next stage
      • get

        T get()
        Gets a result
        Specified by:
        get in interface Supplier<T>
        Returns:
        a result
      • complete

        default boolean complete()
      • done

        static <T> Trampoline<T> done​(T result)