feat(kernel/replace_fn): add template replace that captures commonly used pattern

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>