From 453d2d5bb0069904256cd88f07b0d0e9935e4e0a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 19 Dec 2019 21:08:59 +0100 Subject: Implement `Command::map` --- core/src/command.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 Command { } } + /// Applies a transformation to the result of a [`Command`]. + /// + /// [`Command`]: struct.Command.html + pub fn map( + mut self, + f: impl Fn(T) -> A + 'static + Send + Sync, + ) -> Command + 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. /// -- cgit