Today, I’ll present one of my favorite syntactic sugars in swift:
While trying to sum the result of all the rectangles in an array, I decided to use functional programming. I recalled watching the
$ shorthand somewhere, so I decided to give it a try, and Voàla. Can’t get better than this.
Let’s write the previous code in the verbose form, and break it down:
So… There are three important shortcuts:
- We add the closure outside the method call
- We get rid of the parameter declaration, and use
- We get rid of