Class Memoizer


  • public class Memoizer
    extends Object
    Memorize function execution result
    Author:
    Warren Zhu
    • Constructor Detail

      • Memoizer

        public Memoizer()
    • Method Detail

      • memoize

        public static <T,​R> Function<T,​R> memoize​(Function<T,​R> fn)
        Memoizes a function.
        Type Parameters:
        T - Input type for the function.
        R - Output type for the function.
        Parameters:
        fn - The function to memoize.
        Returns:
        The memoized function.
      • memoize

        public static <T,​R> Function<T,​R> memoize​(Map<T,​R> map,
                                                              Function<T,​R> fn)
        Memoizes a function into a specific cache map.
        Type Parameters:
        T - Input type for the function.
        R - Output type for the function.
        Parameters:
        map - The memoize cache map.
        fn - The function to memoize.
        Returns:
        The memoized function.
      • memoize

        public static <T,​U,​R> BiFunction<T,​U,​R> memoize​(BiFunction<T,​U,​R> biFunction)
        Memoizes a bi-function.
        Type Parameters:
        T - First input type for the function.
        U - Second input type for the function.
        R - Output type for the function.
        Parameters:
        biFunction - The bi-function to memoize.
        Returns:
        The memoized bi-function.
      • memoize

        public static <T,​U,​R> BiFunction<T,​U,​R> memoize​(Map<Tuple<T,​U>,​R> map,
                                                                                BiFunction<T,​U,​R> biFunction)
        Memoizes a bi-function into a specific cache map.
        Type Parameters:
        T - First input type for the function.
        U - Second input type for the function.
        R - Output type for the function.
        Parameters:
        map - The memoize cache map.
        biFunction - The bi-function to memoize.
        Returns:
        The memoized bi-function.