[swift-evolution] [swift-evolution-announce] [Review] SE-0047 Defaulting non-Void functions so they warn on unused results

Haravikk swift-evolution at haravikk.me
Thu Mar 17 05:50:40 CDT 2016

> On 17 Mar 2016, at 09:27, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> Have a look at http://www.martinfowler.com/bliki/FluentInterface.html for a good reason to keep "results" discardable.

Ack, hit send before quoting this part to come back to it.

I assume your point here is that having to add @discardableResult (or whatever) will lead to fluent interfaces becoming prone to the same mistakes that non-fluent interfaces currently have with @warn_unused_result.

Perhaps we could add some kind of attribute to the type itself to allow for selection between the two behaviours?

For example, we could use a different attribute in the style of:


Add this to a function and it affects that specifically, add it to a type and it affects all methods of that type (unless they have their own attribute overriding it). So for a fluent interface I could do:

	protocol MyFluentType {
		func something() -> Self
		func somethignElse() -> Self

		func notAFluentMethod() -> Self

If we do get return type attributes then the return type form could become @unused(ignore) to make it a bit shorter?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160317/5a09dbad/attachment.html>

More information about the swift-evolution mailing list