bevy/crates/bevy_ecs/src
JoJoJet 0c98f9a225 Add AND/OR combinators for run conditions (#7605)
# Objective

Fix #7584.

## Solution

Add an abstraction for creating custom system combinators with minimal boilerplate. Use this to implement AND/OR combinators. Use this to simplify the implementation of `PipeSystem`.

## Example

Feel free to bikeshed on the syntax.

I chose the names `and_then`/`or_else` to emphasize the fact that these short-circuit, while I chose method syntax to empasize that the arguments are *not* treated equally.

```rust
app.add_systems((
    my_system.run_if(resource_exists::<R>().and_then(resource_equals(R(0)))),
    our_system.run_if(resource_exists::<R>().or_else(resource_exists::<S>())),
));
```

---

## Todo

- [ ] Decide on a syntax
- [x] Write docs
- [x] Write tests

## Changelog

+ Added the extension methods `.and_then(...)` and `.or_else(...)` to run conditions, which allows combining run conditions with short-circuiting behavior.
+ Added the trait `Combine`, which can be used with the new `CombinatorSystem` to create system combinators with custom behavior.
2023-02-20 18:16:11 +00:00
..
entity introduce EntityLocation::INVALID const and adjust Entities::get comment (#7623) 2023-02-18 21:15:57 +00:00
query Deprecate ChangeTrackers<T> in favor of Ref<T> (#7306) 2023-02-19 16:19:56 +00:00
schedule Add AND/OR combinators for run conditions (#7605) 2023-02-20 18:16:11 +00:00
storage add len, is_empty, iter method on SparseSets, make SparseSets inspect… (#7638) 2023-02-15 23:52:02 +00:00
system Add AND/OR combinators for run conditions (#7605) 2023-02-20 18:16:11 +00:00
world Implement FromWorld for WorldId (#7726) 2023-02-20 15:02:16 +00:00
archetype.rs use bevy_utils::HashMap for better performance. TypeId is predefined … (#7642) 2023-02-15 04:19:26 +00:00
bundle.rs implement TypeUuid for primitives and fix multiple-parameter generics having the same TypeUuid (#6633) 2023-02-16 17:09:44 +00:00
change_detection.rs Deprecate ChangeTrackers<T> in favor of Ref<T> (#7306) 2023-02-19 16:19:56 +00:00
component.rs add len, is_empty, iter method on SparseSets, make SparseSets inspect… (#7638) 2023-02-15 23:52:02 +00:00
event.rs IntoIterator for EventReader (#7720) 2023-02-17 15:37:36 +00:00
lib.rs Add AND/OR combinators for run conditions (#7605) 2023-02-20 18:16:11 +00:00
reflect.rs Rename UnsafeWorldCellEntityRef to UnsafeEntityCell (#7568) 2023-02-11 18:50:41 +00:00
removal_detection.rs Make RemovedComponents mirror EventReaders api surface (#7713) 2023-02-17 00:01:13 +00:00