-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add UISwitch on's property #97
Conversation
property <~ rex_controlEvents(.ValueChanged) | ||
.map { $0 as? UISwitch } | ||
.ignoreNil() | ||
.map { $0.on } |
There was a problem hiding this comment.
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 }
There was a problem hiding this comment.
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 👍
32e55c4
to
279dbbf
Compare
|
||
property <~ rex_controlEvents(.ValueChanged) | ||
.filterMap { $0 as? UISwitch } | ||
.map { $0.on } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ✨
No description provided.