<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "swift: -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/LazySequenceProtocol/flatMap(_:)-11y2e",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s20LazySequenceProtocolPsE7flatMapys0aeB0Vys0a6FilterB0VyAEy8ElementsQzqd__SgGGqd__GAJ7ElementQzclF"
  },
  "title" : "flatMap(_:)"
}
-->

# flatMap(_:)

Returns the non-`nil` results of mapping the given transformation over
this sequence.

```
func flatMap<ElementOfResult>(_ transform: @escaping (Self.Elements.Element) -> ElementOfResult?) -> LazyMapSequence<LazyFilterSequence<LazyMapSequence<Self.Elements, ElementOfResult?>>, ElementOfResult>
```

## Parameters

`transform`

A closure that accepts an element of this sequence
as its argument and returns an optional value.

## Discussion

Use this method to receive a sequence of non-optional values when your
transformation produces an optional value.

> Complexity: O(1)

---

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)