reccursive implementation of element wise function [skip ci]