DioxusLabs / DioxusLabs/dioxus
Ability to derive a `Signal` while dropping some values
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Specific Demand
Analogous to `map` (#1537), I'd like a way to produce a new signal that contains only a subset of values set in the original signal, potentially mapped over to a new type, `U`. This analogous to Rust's `filter_map` semantics
cf. discussion at https://github.com/DioxusLabs/dioxus/pull/1537#issuecomment-1769205030
## Implement Suggestion
```rust
fn signal_filter_map(cx: Scope, sig: Signal, initial: U, f: F) -> Signal
where
F: Fn(T) -> Option + 'static,
T: Copy,
{
let res: Signal = use_signal(cx, || initial);
dioxus_signals::use_effect(cx, move || {
let value = *sig.read();
if let Some(value) = f(value) {
res.set(value);
}
});
res
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.