@Test public void test_invocation_remembers() { final MemoidOne<Integer, String> memoid = new MemoidOne<>(new Function<Integer, String>() { private int invocation_count = 0; @Override public String apply(Integer i) { assertEquals("Memoid must skip subsequent invocations, it has been invoked before", 0, invocation_count); ++invocation_count; return i.toString(); } }); assertEquals("first invocation (will trigger invocation of wrapped function)", "19", memoid.apply(19)); assertEquals("second invocation (won't trigger invocation)", "19", memoid.apply(19)); assertEquals("third invocation (won't trigger invocation)", "19", memoid.apply(19)); }
@Override public Output apply(Input input) { if (input == null) return fn_.apply(input); return match_(input) .orElseGet(() -> derive_(input)) .getOutput(); }
MemoidOne implements Function<Input, Output> { @Override public Output apply(Input input) { if (input == null) return fn_.apply(input); return match_(input) .orElseGet(() -> derive_(input)) .getOutput(); } }
MemoidOne implements Function<Input, Output> { @Override public Output apply(Input input) { if (input == null) return fn_.apply(input); return match_(input) .orElseGet(() -> derive_(input)) .getOutput(); } MemoidOne(Function<? super Input, ? extends Output> fn);  MemoidOne(Function<? super Input, ? extends Output> fn, BiPredicate<Input, Input> equality); }
MemoidOne implements Function<Input, Output> { @Override public Output apply(Input input) { if (input == null) return fn_.apply(input); return match_(input) .orElseGet(() -> derive_(input)) .getOutput(); } MemoidOne(Function<? super Input, ? extends Output> fn);  MemoidOne(Function<? super Input, ? extends Output> fn, BiPredicate<Input, Input> equality); @Override Output apply(Input input); }
MemoidOne implements Function<Input, Output> { @Override public Output apply(Input input) { if (input == null) return fn_.apply(input); return match_(input) .orElseGet(() -> derive_(input)) .getOutput(); } MemoidOne(Function<? super Input, ? extends Output> fn);  MemoidOne(Function<? super Input, ? extends Output> fn, BiPredicate<Input, Input> equality); @Override Output apply(Input input);  }