---
title: UnfoldSequence
framework: swift
role: symbol
role_heading: Structure
path: swift/unfoldsequence
---

# UnfoldSequence

A sequence whose elements are produced via repeated applications of a closure to some mutable state.

## Declaration

```swift
@frozen struct UnfoldSequence<Element, State>
```

## Overview

Overview The elements of the sequence are computed lazily and the sequence may potentially be infinite in length. Instances of UnfoldSequence are created with the functions sequence(first:next:) and sequence(state:next:).

## Topics

### Type Aliases

- [UnfoldFirstSequence](swift/unfoldfirstsequence.md)
- [UnfoldSequence.Iterator](swift/unfoldsequence/iterator.md)

### Instance Methods

- [next()](swift/unfoldsequence/next().md)

### Default Implementations

- [Sequence Implementations](swift/unfoldsequence/sequence-implementations.md)

## Relationships

### Conforms To

- [IteratorProtocol](swift/iteratorprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)

## See Also

### Wrappers for Algorithms

- [CollectionDifference](swift/collectiondifference.md)
- [DropFirstSequence](swift/dropfirstsequence.md)
- [DropWhileSequence](swift/dropwhilesequence.md)
- [EnumeratedSequence](swift/enumeratedsequence.md)
- [FlattenCollection](swift/flattencollection.md)
- [FlattenSequence](swift/flattensequence.md)
- [JoinedSequence](swift/joinedsequence.md)
- [PrefixSequence](swift/prefixsequence.md)
- [Repeated](swift/repeated.md)
- [ReversedCollection](swift/reversedcollection.md)
- [StrideTo](swift/strideto.md)
- [StrideThrough](swift/stridethrough.md)
- [Zip2Sequence](swift/zip2sequence.md)
