ReactiveObjC
ReactiveObjC copied to clipboard
Generics in `map:`
@erichoracek, @mdiep Can ReactiveObjC
use generics for map:
-like operators as well, in way described here (use additional mapper wrapper for strict type checking)? Disadvantage of that approach -- it can't be done implicitly.
Maybe, use some macros to avoid prefix notation?
So something like
[signal map:^OutputType(InputType obj) { ... }]
should be expanded by macro to something like
[ ({ Mapper<InputType, OutputType> *mapper = Mapper.new; })
map: signal
withBlock: ^OutputType(InputType obj) { ... } ]
// or even (Signal already have one generic, so Mapper may just inherit it):
//
// [ ({ Mapper<OutputType> *mapper = [Mapper mapperWithSignal:signal]; }) map:
// ^OutputType(InputType obj) { ... } ]
//
Or use type casting instead of scopes: [ ((Mapper<InputType, OutputType> *)Mapper.new) map...
It will be even easier:
replace just
signal map:^OutputType
by
((Mapper<OutputType> *)Mapper mapperWithSignal:signal]).map:^OutputType
However, it may broke -map:
autocompletion, but compiler will check return value to match proper generic.
I don't think it's worth the time to try to build something like this for Objective-C—especially since this concept can't be implemented cleanly. IMO you're better off spending that time trying to migrate your code to Swift.
I can't migrate to Swift until it have backward binary compatibility. Anyway, ObjC still here, and would be nice to have type safe map:
for it too.