---
title: next()
framework: swift
role: symbol
role_heading: Instance Method
path: swift/asyncthrowingcompactmapsequence/iterator/next()
---

# next()

Produces the next element in the compact map sequence.

## Declaration

```swift
mutating func next() async throws -> ElementOfResult?
```

## Discussion

Discussion This iterator calls next() on its base iterator; if this call returns nil, next() returns nil. Otherwise, next() calls the transforming closure on the received element, returning it if the transform returns a non-nil value. If the transform returns nil, this method continues to wait for further elements until it gets one that transforms to a non-nil value. If calling the closure throws an error, the sequence ends and next() rethrows the error.
