Last active
March 13, 2017 16:49
-
-
Save hborders/f378b4e0d0f1d74ff7c8149cb04c6268 to your computer and use it in GitHub Desktop.
An Objective-C pattern for making sum types - ExampleSwitcher.h
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
#import "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a | |
@interface ExampleSwitcher<ReturnType : NSObject *> : NSObject | |
+ (instancetype _Nonnull)new NS_UNAVAILABLE; | |
- (instancetype _Nonnull)init NS_UNAVAILABLE; | |
+ (ReturnType _Nonnull)nonnullValueFrom:(Example * _Nonnull)example | |
switchFoo:(ReturnType _Nonnull (^ _Nonnull)(ExampleFoo * _Nonnull foo_))fooBlock | |
bar:(ReturnType _Nonnull (^ _Nonnull)(ExampleBar * _Nonnull bar_))barBlock; | |
+ (ReturnType _Nullable)nullableValueFrom:(Example * _Nonnull)example | |
switchFoo:(ReturnType _Nullable (^ _Nonnull)(ExampleFoo * _Nonnull foo_))fooBlock | |
bar:(ReturnType _Nullable (^ _Nonnull)(ExampleBar * _Nonnull bar_))barBlock; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment