summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-19 21:08:59 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-19 21:08:59 +0100
commit453d2d5bb0069904256cd88f07b0d0e9935e4e0a (patch)
treea92928b4f387f39916e0edffe893deb575e7f318
parent773a23630be538372d5dd1a609d654a1289be389 (diff)
downloadiced-453d2d5bb0069904256cd88f07b0d0e9935e4e0a.tar.gz
iced-453d2d5bb0069904256cd88f07b0d0e9935e4e0a.tar.bz2
iced-453d2d5bb0069904256cd88f07b0d0e9935e4e0a.zip
Implement `Command::map`
-rw-r--r--core/src/command.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/core/src/command.rs b/core/src/command.rs
index e0e5ab5c..b4aa19cc 100644
--- a/core/src/command.rs
+++ b/core/src/command.rs
@@ -34,6 +34,31 @@ impl<T> Command<T> {
}
}
+ /// Applies a transformation to the result of a [`Command`].
+ ///
+ /// [`Command`]: struct.Command.html
+ pub fn map<A>(
+ mut self,
+ f: impl Fn(T) -> A + 'static + Send + Sync,
+ ) -> Command<A>
+ where
+ T: 'static,
+ {
+ let f = std::sync::Arc::new(f);
+
+ Command {
+ futures: self
+ .futures
+ .drain(..)
+ .map(|future| {
+ let f = f.clone();
+
+ future.map(move |result| f(result)).boxed()
+ })
+ .collect(),
+ }
+ }
+
/// Creates a [`Command`] that performs the actions of all the given
/// commands.
///