# tf.data.experimental.get_next_as_optional

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/data/ops/iterator_ops.py#L981-L997) |

Returns a [`tf.experimental.Optional`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/experimental/Optional) with the next element of the iterator. (deprecated)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.data.experimental.get_next_as_optional`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/get_next_as_optional)

<br />

    tf.data.experimental.get_next_as_optional(
        iterator
    )

> [!WARNING]
> **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.data.Iterator.get_next_as_optional()`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/data/Iterator#get_next_as_optional) instead.

If the iterator has reached the end of the sequence, the returned
[`tf.experimental.Optional`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/experimental/Optional) will have no value.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `iterator` | A [`tf.data.Iterator`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/data/Iterator). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A [`tf.experimental.Optional`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/experimental/Optional) object which either contains the next element of the iterator (if it exists) or no value. ||

<br />