# Adding firstAs() to Sequence

**URL:** <https://forums.swift.org/t/adding-firstas-to-sequence/36665>\
**Category:** Pitches\
**Created:** [May 20, 2020, 3:13am UTC](https://forums.swift.org/t/adding-firstas-to-sequence/36665 "2020-05-20T03:13:36Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![timv](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/timv/32/13304_2.png) [@timv](https://forums.swift.org/u/timv)\
**Post date:** [May 21, 2020, 2:46am UTC](https://forums.swift.org/t/adding-firstas-to-sequence/36665/17 "2020-05-21T02:46:47Z")

</div>

> [@David\_Catmull](#):
>
> 👍 That's another one that I have under a slightly different name:
> 
> ```swift
> func firstResult<T>(_ predicate: (Element) -> T?) -> T?
> {
> return lazy.compactMap(predicate).first
> }
> 
> ```

Fun fact! This version isn't actually lazy. `LazySequenceProtocol.compactMap` takes an escaping closure, which this `predicate` isn't, so the `compactMap` is silently inferred to be the regular `Sequence.compactMap`.

---

_[View the full topic](https://forums.swift.org/t/adding-firstas-to-sequence/36665)._
