-
Notifications
You must be signed in to change notification settings - Fork 37
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
Signal filter_map problem #59
Comments
Yes, that is expected. A Signal is similar to a mutable variable, it must always have a value. So if the The purpose of |
Yes I agree, but the behavior that I am experiencing is that the result of |
The some_signal
.filter_map(|_| Some(5))
.map(|x| {
// x == Some(5)
}) If the input is some_signal
.filter_map(|value| value)
.map(|x| {
// x: Option<A>
}) If you want to do some sort of transformation on it, then you should use the some_signal.filter_map(|value| {
value.and_then(|value| {
Some(value + 5)
})
}) Or you can use some_signal.filter_map(|value| {
let value = value?;
Some(value + 5)
}) |
Ok, but why pass the For example here, the some_signal
.filter_map(|value| if value > 5 {Some(value - 5)} else {None})
.map(|value| value*10) But currently the code would need to look something like you wrote earlier: some_signal
.filter_map(|value| if value > 5 {Some(value - 5)} else {None})
.map(|value| {
let val = value?;
val*10}) Which I think is unnecessary, or is there some other use case where this might be helpful? |
Like I said, the reason is to avoid unnecessary updates. If There are several methods that don't change the value, they exist only to prevent unnecessary updates, such as
As I said before, that is not possible. A Signal must always have a value. If the |
I think I understand now, but I needed to go over the code once again. As I understand it, the problem comes from one situation and that is on the beginning. If for the very first value the
This sentence confused me and now I understand :) , because this is on the very beginning when no values were returned as Thank you for your patience with me. |
That's correct. That's also why Perhaps it would make sense to rename |
I think the name is fine and it makes sense, now that I understand what is the point. But it may be confusing, for others that expect it to behave like standard |
Your assumption is correct, the Perhaps what you're misunderstanding is how the In the case of This is similar to how You're not supposed to call some_signal
.filter_map(|_| Some(5))
.for_each(|value| {
// value == Some(5)
async {}
}) Of course the other combinators also unwrap the first |
Hello, I used the filter_map function on cloned signal and the output it provides is encapsulated in Option, instead of filter disposing of the Option as is in normal iterator filter_map function.
I managed to obtain desired result with this change to Signal trait implementation for FilterMap:
I don't know if the current behavior is desired or not, maybe I am just not understanding this function correctly.
The text was updated successfully, but these errors were encountered: