Skip to content

Result in filter_map_async #697

Answered by WaffleLapkin
vtvz asked this question in Q&A
Discussion options

You must be logged in to vote

I think this was already answered in telegram, but I'll answer it here too, so other users can find this too.

One way to handle these three cases (db error, some data, no data) is to first add it to the context with map and then filter the result. So it may look something like this:

type FetchRes = Result<Option<User>, Error>;

async fn fetch_user(/* args */) -> FetchRes { ... }

Update::filter_message()
    .enter_dialogue::<Message, storage::SqliteStorage, DialogueState>()
    .map_async(fetch_user)
        // Filter `Ok(Some(_))`
        .branch(filter_map(|r: FetchRes| r.ok().flatten()).endpoint(with_user))
        // Filter `Ok(None)`
        .branch(filter(|r: FetchRes| matches!(r, Ok(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vtvz
Comment options

Answer selected by vtvz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants