Created
November 28, 2012 04:09
-
-
Save boredzo/4158978 to your computer and use it in GitHub Desktop.
Proposal for a new kind of switch statement
This file contains hidden or 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
| I propose a new statement called (there is a better term for this, but I haven't thought of it) “bitswitch”. | |
| It would work much like a regular switch statement, and could be implemented as a macro on top of it in many languages: | |
| bitswitch(container, test) { | |
| case all: | |
| case single: | |
| case multiple: | |
| case none: | |
| default: //Only meaningful if you don't use all four cases | |
| } | |
| The test should be an expression (in Objective-C and some other languages, it could be a block). It would be applied to every element of the container, and then return one of the aforementioned case values. | |
| This would save running multiple passes over the collection if you have multiple cases to cover. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment