Template pattern functional way