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

Proposal: Flatmap scenarios of preference #17

Open
loganwright opened this issue Feb 22, 2016 · 4 comments
Open

Proposal: Flatmap scenarios of preference #17

loganwright opened this issue Feb 22, 2016 · 4 comments
Labels

Comments

@loganwright
Copy link

For example

if let url = urlString.flatMap({ NSURL(string: $0) }) { ...

is possibly preferable:

if let urlString = urlString, let url = NSURL(string: $0) { ...
@brightredchilli
Copy link

not sure I get the use of flatMap - where is the sequence?

@loganwright
Copy link
Author

@brightredchilli In this case, it's running on an Optional. There's also a flat map on those since I think they conform to CollectionOfOne or some other weird kind of collection protocol.

I believe anything that boxes a value is considered a collection on some level. This one essentially operates on the unwrapped value if one exists.

This is a proposal by the way, I think it warrants discussion.

@loganwright loganwright changed the title Flatmap scenarios of preference Proposal: Flatmap scenarios of preference Feb 23, 2016
@brightredchilli
Copy link

yes i would definitely prefer the second style to the first - for one, flatMap should be flattening(which it isn't), and map should produce an array, even if it's an array of one(which it isn't). Is anyone using flatMap in this manner right now?

@brightredchilli
Copy link

oh never mind, CollectionOfOne has overrides on flatMap. still feels weird though.

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

No branches or pull requests

2 participants