I filed this as rdar://21468140 but I would like to open this up for discussion. I'm probably not the first person to think of this too.
[Swift] Add ability to mark closures as "Functional"
Summary:
It would be nice to be able to mark functions (and generally any closure) as functional. That is having no side effects outside of their scope. I believe Haskell has a similar language feature.
Here's a first stab at how this feature would work:
class foo {
var bar = "Hello"
@functional
func baz() -> Int {
bar = "world"
return 42
}
}
Trying to compile the above code would result in a compile time error along the lines of "baz() is a functional closure and cannot have side effects" on the line where bar is reassigned to "world"