<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UnfoldSequence",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s14UnfoldSequenceV"
  },
  "title" : "UnfoldSequence"
}
-->

# UnfoldSequence

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

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

## 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`](/documentation/Swift/UnfoldFirstSequence)

The return type of `sequence(first:next:)`.

[`Iterator`](/documentation/Swift/UnfoldSequence/Iterator)

A type that provides the sequence’s iteration interface and
encapsulates its iteration state.

## Relationships

### Conforms To

[`Sequence`](/documentation/Swift/Sequence)

[`IteratorProtocol`](/documentation/Swift/IteratorProtocol)

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)