GenuineSounds icon

Untitled

GenuineSounds | PRO | 02/21/15 12:29:27 PM UTC | 0 ⭐ | 644 👁️ | Never ⏰ | []
Java |

420 B

|

None

|

0 👍

/

0 👎

public class MemoFunction<T, U> implements Function<T, U> {
 
    public final Map<T, U> cache = new ConcurrentHashMap<>();
    private final Function<T, U> function;
 
    public MemoFunction(Function<T, U> function) {
        this.function = function;
    }
 
    public Function<T, U> cache() {
        return input -> cache.computeIfAbsent(input, function::apply);
    }
 
    @Override
    public U apply(T t) {
        return function.apply(t);
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎