Last active
August 29, 2015 14:24
-
-
Save coryalder/7fd3105b9db3474e7cfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What's the best syntax for this: | |
// no trailing-closures | |
// explicit about what's happening, but those ()'s aren't needed... can we do better? | |
throwActions.filter({ $0.direction == dir }).map({ $0.action() }) | |
// all trailing closures | |
// weirdly looks like we're mapping the block, rather than the result of filtering throwActions using that block. | |
throwActions.filter { $0.direction == dir }.map { $0.action() } | |
// only trailing-closure syntax on the *trailing* closure? | |
// weird to mix and match syntax, but at least it's clearer what we're mapping | |
throwActions.filter({ $0.direction == dir }).map { $0.action() } | |
// all trailing, each on it's own line | |
// not bad... very javascript-y. Suggested by @JohnRHeaton when I asked about this on Twitter | |
throwActions | |
.filter { $0.direction == dir } | |
.map { $0.action() } | |
// don't chain functions | |
// is this too explicit? It means we have to come up with names for any/all intermediate steps. | |
let filteredActions = throwActions.filter { $0.direction == dir } | |
filteredActions.map { $0.action() } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment