fold_map implementation