foldl1 implementation