[swift-evolution] Disambiguate Return Type With Void
Антон Жилин
antonyzhilin at gmail.com
Tue Apr 26 12:41:16 CDT 2016
Let's expand on that situation. Dictionary would have these methods:
@discardableResult func removeValue(forKey key: Key) -> Value?
func removeValue(forKey key: Key) -> Self
I would argue that these two versions are not semantically identical: (1)
returns removed value while (2) does not.
Therefore they should have different names. In this case, we can rename
them like this:
@discardableResult func removeValue(forKey key: Key) -> Value?
func remove(key key: Key) -> Self
Or like this:
func removeValue(forKey key: Key) -> Value?
func remove(key key: Key) -> Void
func remove(key key: Key) -> Self
- Anton
2016-04-26 19:26 GMT+03:00 Jordan Rose <jordan_rose at apple.com>:
>
> On Apr 26, 2016, at 06:57, Антон Жилин via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> +1
>
> > Also, technically we can assign a value to Void function
> This proposal will not disallow that. Just non-Void functions will be
> preferred when result is used.
>
> array.sort(..) // mutating
> let array2 = array.sort(..) // non-mutating, instead of array.sorted()
>
> I think, that's actually the best solution to mutating / non-mutating convention!
>
> There are mutating methods that have return values, like
> Dictionary.removeValue(forKey:). Admittedly there’s no non-mutating version
> of that at the moment, but that doesn’t mean there couldn’t be.
>
> Jordan
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160426/47495b9a/attachment.html>
More information about the swift-evolution
mailing list