Mapping function not working if the first example is returned as None

### Describe the bug

https://github.com/huggingface/datasets/blob/8a19de052e3d79f79cea26821454bbcf0e9dcd68/src/datasets/arrow_dataset.py#L3652C29-L3652C37

Here we can see the writer is initialized on `i==0`. However, there can be cases where in the user mapping function, the first example is filtered out (length constraints, etc).

In this case, the writer would be a `None` type and the code will report `NoneType has no write function`.

A simple fix is available, simply change line 3652 from `if i == 0:` to `if writer is None:`

### Steps to reproduce the bug

Prepare a dataset

have this function

```
import datasets


def make_map_fn(split, max_prompt_tokens=3):
    def process_fn(example, idx):

        question = example['question']
        reasoning_steps = example['reasoning_steps']
        label = example['label']

        answer_format = ""
        for i in range(len(reasoning_steps)):
            system_message = "Dummy"

        all_steps_formatted = []

        content = f"""Dummy"""

        prompt = [
            {"role": "system", "content": system_message},
            {"role": "user", "content": content},
        ]
        tokenized = tokenizer.apply_chat_template(prompt, return_tensors="pt", truncation=False)
        if tokenized.shape[1] > max_prompt_tokens:
            return None  # skip overly long examples

        data = {
            "dummy": "dummy"
        }

        return data

    return process_fn

...
# load your dataset
...
train = train.map(function=make_map_fn('train'), with_indices=True)
```

### Expected behavior

The dataset mapping shall behave even when the first example is filtered out.

### Environment info

I am using `datasets==3.6.0` but I have observed this issue in the github repo too: https://github.com/huggingface/datasets/blob/8a19de052e3d79f79cea26821454bbcf0e9dcd68/src/datasets/arrow_dataset.py#L3652C29-L3652C37

Comments:
Hi, map() always expect an output.

If you wish to filter examples, you should use filter(), in your case it could be something like this:

```python
ds = ds.map(my_processing_function).filter(ignore_long_prompts)
```

Realized this! Thanks a lot, I will close this issue then.

@dnaihao, thanks for reporting. Finally found an answer to my question. Spend quite a lot of time trying to debug:

```
    new_ds = dataset.map(
             ^^^^^^^^^^^^
  File "/home/ubuntu/ml/notebooks/scripts/env_ml/lib/python3.12/site-packages/datasets/dataset_dict.py", line 953, in map
    dataset_dict[split] = dataset.map(
                          ^^^^^^^^^^^^
  File "/home/ubuntu/ml/notebooks/scripts/env_ml/lib/python3.12/site-packages/datasets/arrow_dataset.py", line 562, in wrapper
    out: Union["Dataset", "DatasetDict"] = func(self, *args, **kwargs)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/ml/notebooks/scripts/env_ml/lib/python3.12/site-packages/datasets/arrow_dataset.py", line 3343, in map
    for rank, done, content in Dataset._map_single(**unprocessed_kwargs):
  File "/home/ubuntu/ml/notebooks/scripts/env_ml/lib/python3.12/site-packages/datasets/arrow_dataset.py", line 3691, in _map_single
    writer.write(example)
    ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'write'
```

@lhoestq @dnaihao - Flagging this issue again. (.map with return None is a very common approach that I have seen, so it was very non-obvious to find this issue). Is there a way of highlighting this better in the documentation / adding this as a feature @lhoestq?

Let me reopen the issue so that @lhoestq can probably notice it :)