Rewrite of the inject method of Array