# Preparing the iteration ABI for move-only types

**URL:** <https://forums.swift.org/t/preparing-the-iteration-abi-for-move-only-types/12980>\
**Category:** Compiler\
**Created:** [May 25, 2018, 7:06pm UTC](https://forums.swift.org/t/preparing-the-iteration-abi-for-move-only-types/12980 "2018-05-25T19:06:49Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ben-cohen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ben-cohen/32/296_2.png) [@ben-cohen](https://forums.swift.org/u/ben-cohen)\
**Post date:** [May 30, 2018, 12:06am UTC](https://forums.swift.org/t/preparing-the-iteration-abi-for-move-only-types/12980/5 "2018-05-30T00:06:09Z")

</div>

> [@Joe\_Groff](#):
>
> `Collection.first` is a property requirement of type `Element?` . For most collection implementations that store non-optional `Element` s, this wouldn't be implementable, since you'd somehow have to form a temporary `Optional<Element>` value without modifying the collection or copying the element out of it.

`.first` is one of the dubious customization points that probably [should be dropped](https://github.com/apple/swift/pull/16809).

Would it make a difference if it were a `set` as well as a `get` computed property? That's been considered in the past as separately useful. Then maybe getting it for a move-only collection could also use the set part to consume the collection.

> [@Joe\_Groff](#):
>
> `SetAlgebra.insert` has the signature `mutating func insert(_ newMember: Element) -> (inserted: Bool, memberAfterInsert: Element)` , where the return tuple contains either the new member inserted, or the old member already in the set. This is not implementable for a move-only element since the value would have to be copied out of the set to be returned.

I guess this would need to be converted to return `Element?`, with `nil` for nothing displaced.

---

_[View the full topic](https://forums.swift.org/t/preparing-the-iteration-abi-for-move-only-types/12980)._
