Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NSObject+RACFastEnumeration #108

Closed
jspahrsummers opened this issue Nov 6, 2012 · 11 comments
Closed

Remove NSObject+RACFastEnumeration #108

jspahrsummers opened this issue Nov 6, 2012 · 11 comments
Assignees

Comments

@jspahrsummers
Copy link
Member

The rac_toSubscribable method is pretty similar to the rac_sequence functionality provided on the built-in collection classes. Arguably, the laziness of rac_sequence also leads to a better API.

@Coneko
Copy link
Member

Coneko commented Nov 8, 2012

Is there going to be a method to get a subscribable from a sequence?
I'm using rac_toSubscribable to work with arrays of subscribables by converting them to subscribables of subscribables and then back to arrays.

@jspahrsummers
Copy link
Member Author

There's not really a sane way to do that, given that sequences are meant to be used lazily. I would recommend instead setting up APIs to use <RACStream> and not care about the specific stream type.

@joshaber
Copy link
Member

joshaber commented Nov 8, 2012

Though you can't really use subscribables and sequences interchangeably since the accessing is different.

@jspahrsummers
Copy link
Member Author

@Coneko Is there any reason not to use a sequence of subscribables for the case you describe?

@Coneko
Copy link
Member

Coneko commented Nov 8, 2012

I can't -flattenMap: a sequence of subscribables, but I guess I could always use -map: on the sequence and then call +merge: with the resulting array.
Although +merge: itself is implemented through -rac_toSubscribable and -flatten.
Is that going to go too? I use that quite a bit as well.

@jspahrsummers
Copy link
Member Author

Maybe the right answer here is to move -first, -array, etc. into <RACStream> proper, so that values can be retrieved from streams in a generic way.

@Coneko
Copy link
Member

Coneko commented Nov 9, 2012

It doesn't really relate to those in my case.

I use +merge: when I want to subscribe with the same subscriber to multiple subscribables. For example several NSNotificationCenter notifications, where the selective logic is dependent on the properties of the notification rather than the source of it.

I use -rac_toSubscribable followed by -flatten when I have arrays of asynchronous tasks, or of objects on which I have to execute asynchronous tasks. The interface for those are subscribables that send a next with the result of the computation, or just error or completed if the task is a side effect.
So basically it goes array of objects -> -rac_toSubscribable -> subscribable of objects -> -map:, -filter:, etc -> subscribable of tasks -> -flatten, -catch:, etc -> subscribable of results -> -toArray, -finally:, -subscribeCompleted:, etc -> array of results. I actually don't use toArray because it deadlocks in most of those cases, but I use something equivalent.
I find it pretty handy, but I guess it doesn't really fit in the subscribables are a push-based stream of values view.

@jspahrsummers
Copy link
Member Author

I'll add sequence <-> subscribable conversion methods to #92, I think, and then still remove rac_toSubscribable from NSObject. That seems to be the best way forward, since it discourages turning arrays into subscribables, but still provides a way to do it.

@Coneko
Copy link
Member

Coneko commented Nov 9, 2012

Works for me. I'll probably start using sequences in many places where I'm using arrays now once that one goes through anyway.

@thenikso
Copy link
Contributor

Why converting an array to a subscribable instead of a sequence should be discouraged?

Aren't those to be seen as two different instances of the RACStream monad that you can pick an choose depending on your needs?

As @Coneko is saying, building subscribables starting form an array is a pretty common task in here.

@jspahrsummers
Copy link
Member Author

@thenikso Sequences form a better abstraction for arbitrary computation, while subscribables are better for asynchronous or reactive streams of values.

It's not that arrays shouldn't be used as subscribables — simply that sequences make more sense for most such cases, and so should be the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants