Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

Closure passed to flatMap needs return type specified? #9

Closed
wvteijlingen opened this issue Sep 12, 2014 · 2 comments
Closed

Closure passed to flatMap needs return type specified? #9

wvteijlingen opened this issue Sep 12, 2014 · 2 comments

Comments

@wvteijlingen
Copy link
Contributor

Maybe I'm missing something here, but it seems like I must specify the return type of the closure passed to flatMap. When I use just the parameters, it fails to build with error: "Missing argument for parameter 'f' in call".

Doesn't work:

Artist.findOne("1").flatMap { resource, meta in
    return resource.findRelated("albums")
}

Does work:

Artist.findOne("1").flatMap { resource, meta -> Future<([Resource], Meta?)> in
    return resource.findRelated("albums")
}
@wvteijlingen wvteijlingen changed the title flatMap closure needs return type specified? Closure passed to flatMap needs return type specified? Sep 12, 2014
@Thomvis
Copy link
Owner

Thomvis commented Sep 12, 2014

I think Swift only is able to deduce the type of a closure if it is a single expression, without return.

This does not work:

future(1).flatMap { num in
    return Future.succeeded(num);
}

This does work:

future(1).flatMap { num in
   Future.succeeded(num);
}

So, I'm guessing that this will also work:

Artist.findOne("1").flatMap { resource, meta in
   resource.findRelated("albums")
}

@wvteijlingen
Copy link
Contributor Author

You're right! Weird though, because the second closure has a return as well, it's just implicit.

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

No branches or pull requests

2 participants