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 UISwitch on's property #97

Merged
merged 2 commits into from
Apr 11, 2016

Conversation

dmcrodrigues
Copy link
Contributor

No description provided.

property <~ rex_controlEvents(.ValueChanged)
.map { $0 as? UISwitch }
.ignoreNil()
.map { $0.on }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of:

.map { $0 as? UISwitch }
.ignoreNil()

You can go with:

.filterMap { $0 as? UISwitch }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's pretty neat 👍


property <~ rex_controlEvents(.ValueChanged)
.filterMap { $0 as? UISwitch }
.map { $0.on }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can take this one step further and put it all in the filterMap

.filterMap { ($0 as? UISwitch)?.on }

I like to minimize the number of operators where possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll unify it with the filterMap like you suggested. I personally prefer having this kind of separation but makes sense minimize.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chained *map operators do look a bit cleaner and make sense semantically. However, signal transformations do have a real cost and can add up perf wise so I like to collapse them. In an ideal world there would be a way that happened automatically. But that's a personal pipe dream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, it's definitely something to consider! And that dream, I hope it becomes reality one day ✨

@neilpa neilpa merged commit e82efea into RACCommunity:master Apr 11, 2016
@dmcrodrigues dmcrodrigues deleted the dr/uiswitch-on-property branch April 11, 2016 19:05
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

Successfully merging this pull request may close these issues.

3 participants