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

Add 'do' syntax for <RACStream> #109

Closed
jspahrsummers opened this issue Nov 7, 2012 · 5 comments
Closed

Add 'do' syntax for <RACStream> #109

jspahrsummers opened this issue Nov 7, 2012 · 5 comments

Comments

@jspahrsummers
Copy link
Member

It'd be totally possible to add a do syntax for the <RACStream> monad, though it'd have to work a bit more like Clojure's domonad than Haskell's do statement.

But I'm wondering whether this would even be useful. How often would people be repeatedly binding in a way that this would be valuable?

@Coneko
Copy link
Member

Coneko commented Nov 7, 2012

I don't think a traditional do syntax would be very useful in objc.

If all you're doing is chaining bind:s, the syntax would be just a bit lighter, but the general readability would suffer because of it's inconsistency with the rest of the code.
If you're composing bind:s, objc already allows you to assign the result of bind:s to variables, so there's no need for a <- operator.

What really hurts readability as it is now, is splitting and merging streams through publish and combineLatest:, or working with a lot of tuples to avoid doing that. Especially since objc's type signatures don't allow you to specify what is in the tuples.

@jspahrsummers
Copy link
Member Author

If you're composing bind:s, objc already allows you to assign the result of bind:s to variables, so there's no need for a <- operator.

This is a little bit of a red herring, because:

do
    x <- M
    

maps to something like the following Objective-C:

[M bind:^(id x) {
    …
}];

That said, I agree with your overall point. I don't think do syntax would be that useful for how RAC is generally going to be used.

@joshaber
Copy link
Member

joshaber commented Nov 8, 2012

I think the value of do syntax is that deeply nested binds are gross.

So, compare:

do 
    x <- f1
    y <- f2 x
    z <- f3 x y
    return x + y + z

vs.

[[self f1] bind:^(id x) {
    return [[self f2:x] bind:^(id y) {
        return [[self f3:x and:y] bind:^(id z) {
            return [self.class return:[[x plus:y] plus:z]];
        }];
    }];
}];

Nesting aspolsion.

The question in my mind is whether a macro could be better enough to make it worthwhile.

@jspahrsummers
Copy link
Member Author

A do macro would end up fairly similar to Clojure's:

do(
    x, [self f1],
    y, [self f2],
    z, [self f3:x and:y],
    [self.class return:[[x plus:y] plus:z]]
)

I just don't think people will be binding that often/intensely.

@joshaber
Copy link
Member

Yeah, I agree. Not much better and probably rare.

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

No branches or pull requests

3 participants