# Add nil-collapsing call expression

**URL:** <https://forums.swift.org/t/add-nil-collapsing-call-expression/14634>\
**Category:** Pitches\
**Created:** [July 20, 2018, 7:13pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634 "2018-07-20T19:13:04Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![DeFrenZ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/defrenz/32/827_2.png) [@DeFrenZ](https://forums.swift.org/u/DeFrenZ)\
**Post date:** [February 28, 2019, 5:45pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/21 "2019-02-28T17:45:20Z")

</div>

I was going to say the same thing, but `Optional.zip` requires that all arguments are `some`, while the proposal allows some to go through as `nil`. So this is fine if you `zip` only the "uncertain" arguments, but not if you `zip` them all

---

<div class="post-metadata">

**Author:** ![mattpolzin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mattpolzin/32/6041_2.png) [@mattpolzin](https://forums.swift.org/u/mattpolzin)\
**Post date:** [February 28, 2019, 6:31pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/22 "2019-02-28T18:31:15Z")

</div>

You just wouldn’t pass the ones you don’t want to be guaranteed to be .some to the zip (you also don’t need to pass things that are not optional to begin with).

```
zip(optionalA, optionalB) { foo($0, $1, otherThing) }

```

---

<div class="post-metadata">

**Author:** ![amnykon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/amnykon/32/5803_2.png) [@amnykon](https://forums.swift.org/u/amnykon)\
**Post date:** [March 1, 2019, 4:14am UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/23 "2019-03-01T04:14:55Z")

</div>

I agree that this is only syntax sugar, but for something that is used so often, the work arounds are

> [@cukr](#):
>
> Still not great.

Especially when there is more than 1 optional argument.

---

<div class="post-metadata">

**Author:** ![adtrevor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adtrevor/32/23769_2.png) [@adtrevor](https://forums.swift.org/u/adtrevor)\
**Post date:** [March 1, 2019, 2:27pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/24 "2019-03-01T14:27:42Z")

</div>

That’s just bikeshedding, but I am worried about using « ¿ », I have never seen it in any programming language and, except for Spanish speakers I don’t think people are generally used to how to type it on their keyboard.

Other than that I would really appreciate this feature to be implemented, it isn’t something I need on an everyday basis, but I have already had several cases where I really felt like my code would have been much cleaner if it existed.  
Ability to collapse per parameter is probably nice to have too.

---

<div class="post-metadata">

**Author:** ![cukr](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cukr/32/889_2.png) [@cukr](https://forums.swift.org/u/cukr)\
**Post date:** [March 1, 2019, 3:14pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/25 "2019-03-01T15:14:40Z")

</div>

> [@adtrevor](#):
>
> I don’t think people are generally used to how to type it on their keyboard.

I think people are generally unable to type it on their keyboard at all. For example it doesn't exist on my keymap (polish pro on mac)

---

<div class="post-metadata">

**Author:** ![amnykon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/amnykon/32/5803_2.png) [@amnykon](https://forums.swift.org/u/amnykon)\
**Post date:** [March 1, 2019, 4:18pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/26 "2019-03-01T16:18:57Z")

</div>

Daniel\_Resnick syntax is much better. Just add a ? to the end of the optional. This is the exact same syntax as forced unwrap. no ¿ is required.

> [@Daniel\_Resnick](#):
>
> func foo(\_ x: Int, \_ y: Int) -\> Int { return x + y }
> 
> let a: Int? = 5  
> let b: Int? = nil
> 
> foo(a?, a?) // =\> 10  
> foo(a?, b?) // =\> nil  
> foo(b?, a?) // =\> nil

---

<div class="post-metadata">

**Author:** ![adtrevor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adtrevor/32/23769_2.png) [@adtrevor](https://forums.swift.org/u/adtrevor)\
**Post date:** [March 1, 2019, 4:19pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/27 "2019-03-01T16:19:09Z")

</div>

Do you mean you can’t type it even with modification keys?

---

<div class="post-metadata">

**Author:** ![cukr](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cukr/32/889_2.png) [@cukr](https://forums.swift.org/u/cukr)\
**Post date:** [March 1, 2019, 4:42pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/28 "2019-03-01T16:42:55Z")

</div>

Yes. I cannot find it on Mac, on Ubuntu with Polish keyboard layout it's right alt+shift+2 and it seems that the only character not printed on a keyboard that I can type in Polish(Programmers) layout on Windows is €

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [March 1, 2019, 6:33pm UTC](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634/29 "2019-03-01T18:33:50Z")

</div>

> [@cukr](#):
>
> For example it doesn't exist on my keymap (polish pro on mac)

> [@adtrevor](#):
>
> Do you mean you can’t type it even with modification keys?

That surprised me too and at first I just thought he did not know how. But I switched to the Polish programming keyboard and @cukr is right.

Though in general, there are ways of [fixing that sort of problem](https://forums.swift.org/t/iscontained-in-array-extension-of-equatable/20223/27)...

[Previous page](https://forums.swift.org/t/add-nil-collapsing-call-expression/14634.md?page=1)
