is there a @rediscardableResult like rethrows?


(David Ungar) #1

I like to use the pipe operator for a functional programming style:

infix operator |> {associativity left precedence 100}

public func |> <A, B> ( x: A, f: @noescape (A) throws -> B ) rethrows -> B {
    return try f(x)
}

It lets me write x |> y |> z instead of z(y(x)) which I much prefer when x is a complicated expression.

The “rethrows” is great because it lets the “throwiness” of the functions shine through.

In my conversion to Swift 3, though, I am missing the same thing for @discardableResult.
I would like to use the same |> operator for functions with or without @discardableResults.
Is there a @rediscardableResult annotation? Or some other way to do this?

Thanks,

- David

- David (from iPad, typos likely)