Skip to content

Add filter_map method to Subscription#2981

Merged
hecrj merged 2 commits intoiced-rs:masterfrom
watsaig:feat/subscription_filter_map
Nov 29, 2025
Merged

Add filter_map method to Subscription#2981
hecrj merged 2 commits intoiced-rs:masterfrom
watsaig:feat/subscription_filter_map

Conversation

@watsaig
Copy link
Contributor

@watsaig watsaig commented Jun 6, 2025

Just a handy way to go from Subscription<A> to Subscription<B> while removing any None values, using StreamExt::filter_map

The main use case is to work with existing subscription functions where one only cares about some values. For example:

fn subscription(&self) -> Subscription<Message> {
    window::events().filter_map(|(id, event)| match event {
        window::Event::Focused => Some(Message::WindowFocused(id)),
        window::Event::Closed => Some(Message::WindowClosed(id)),
        _ => None,
    })
}

Currently, doing this requires a no-op message variant.

@hecrj hecrj force-pushed the feat/subscription_filter_map branch from 91f1111 to 24218c5 Compare November 28, 2025 23:54
@hecrj hecrj added this to the 0.14 milestone Nov 28, 2025
@hecrj hecrj added feature New feature or request subscription addition labels Nov 28, 2025
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

I haven't been a fan of treating subscriptions like composable units in the past; but I can't seem to argue that position reasonably today.

So, what the heck. Let's go ahead with this and see how it goes.

Thanks!

@hecrj hecrj enabled auto-merge November 28, 2025 23:59
@hecrj hecrj merged commit 4f6ccb7 into iced-rs:master Nov 29, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments