protected boolean addFunctionFromCachedRepository(
     final InMemoryCompiledFunctionRepository before,
     final InMemoryCompiledFunctionRepository after,
     final InMemoryCompiledFunctionRepository compiled,
     final FunctionDefinition function,
     final Instant atInstant) {
   if (before != null) {
     final CompiledFunctionDefinition compiledFunction =
         before.findDefinition(function.getUniqueId());
     if (compiledFunction.getLatestInvocationTime() == null) {
       // previous one always valid
       compiled.addFunction(compiledFunction);
       return true;
     } else {
       final Instant validUntil = Instant.of(compiledFunction.getLatestInvocationTime());
       if (!validUntil.isBefore(atInstant)) {
         // previous one still valid
         compiled.addFunction(compiledFunction);
         return true;
       }
     }
   }
   if (after != null) {
     final CompiledFunctionDefinition compiledFunction =
         after.findDefinition(function.getUniqueId());
     if (compiledFunction.getEarliestInvocationTime() == null) {
       // next one always valid
       compiled.addFunction(compiledFunction);
       return true;
     } else {
       final Instant validFrom = Instant.of(compiledFunction.getEarliestInvocationTime());
       if (!validFrom.isAfter(atInstant)) {
         // next one already valid
         compiled.addFunction(compiledFunction);
         return true;
       }
     }
   }
   return false;
 }