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 possibility to use and + or with collection of signals/properties #735

Merged
merged 29 commits into from
Jun 10, 2019
Merged

Add possibility to use and + or with collection of signals/properties #735

merged 29 commits into from
Jun 10, 2019

Conversation

olejnjak
Copy link
Contributor

@olejnjak olejnjak commented May 7, 2019

Usually on my projects I do use more properties to determine state of some Property, e.g. isLoading property usually depends on more properties which later on ends like this

action1.isExecuting.or(action2.isExecuting)...or(actionX.isExecuting)

Then I end up with extensions which simplify such code and I think it might be useful for more people than just me.

This PR adds static function and and or to SignalProducer, PropertyProtocol with appropriate attributes which solves such case elegantly.

Checklist

  • Updated CHANGELOG.md.

internal func and() -> Bool {
return reduce(true) { $0 && $1 }
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer not to add these extensions. They pollute the namespace and aren't used widely enough to justify that—nor do they add that much over .reduce(true, &&).

/// - property: Collection of properties to be combined.
///
/// - returns: A property that contains the logial AND results.
public static func and<P: PropertyProtocol, Properties: Collection>(_ properties: Properties) -> Property<Value> where P.Value == Value, Properties.Element == P {
Copy link
Contributor

Choose a reason for hiding this comment

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

all seems like a better name for this

/// - properties: Collection of properties to be combined.
///
/// - returns: A property that contains the logial OR results.
public static func or<P: PropertyProtocol, Properties: Collection>(_ properties: Properties) -> Property<Value> where P.Value == Value, Properties.Element == P {
Copy link
Contributor

Choose a reason for hiding this comment

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

any seems like a better name for this

@olejnjak
Copy link
Contributor Author

Thanks for the review, all issues should be resolved now.

1. add possibility to use `and` and `or` operators with array of arguments (#735, kudos to @olejnjak)
```swift
let property = Property.or([boolProperty1, boolProperty2, boolProperty3])
```
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be updated now

@mdiep
Copy link
Contributor

mdiep commented May 15, 2019

Looks good to me. I'll leave this open for a day or two in case anyone else has feedback.

@mdiep mdiep merged commit 7763d88 into ReactiveCocoa:master Jun 10, 2019
@mdiep
Copy link
Contributor

mdiep commented Jun 10, 2019

Thanks! Sorry for the delay.

@olejnjak olejnjak deleted the collection_and+or branch June 10, 2019 12:26
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.

None yet

2 participants