From f67d487a8486729c164e3de4b02a70f8b485fb06 Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 10 Nov 2020 17:32:53 +0000 Subject: [PATCH] mutate many --- Cargo.toml | 2 +- src/maybe.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ef892a..f044dc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ad-hoc-iter" -version = "0.2.1" +version = "0.2.2" description = "Ad-hoc exact size owning iterator macro and other optional utils" repository = "https://git.flanchan.moe/flanchan/ad-hoc-iter" keywords = ["iterator", "macro", "iter"] diff --git a/src/maybe.rs b/src/maybe.rs index ce27d84..2e13001 100644 --- a/src/maybe.rs +++ b/src/maybe.rs @@ -134,7 +134,7 @@ where U: IntoIterator false } } - /// Map the single value with this function + /// Map the many value with this function #[inline] pub fn map_many(self, fun: F) -> MaybeMany where F: FnOnce(U) -> A, A: IntoIterator @@ -146,6 +146,16 @@ where U: IntoIterator } } + /// Mutate the many value with this function. + #[inline] pub fn on_many(&mut self, fun: F) -> Option + where F: FnOnce(&mut U) -> A, + { + match self { + Self::Many(ref mut m) => Some(fun(m)), + _ => None + } + } + /// Map the single value with this function #[inline] fn map_one(self, fun: F) -> MaybeMany where F: FnOnce(T) -> T