[swift-users] is there a @rediscardableResult like rethrows?

Chris Lattner clattner at apple.com
Wed Jun 22 19:24:05 CDT 2016


> On Jun 22, 2016, at 10:07 AM, David Ungar via swift-users <swift-users at swift.org> wrote:
> 
> 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?

There is nothing like this at present, you need to use the "_ =“ pattern.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160622/5a82db76/attachment.html>


More information about the swift-users mailing list