+ /// An iterator method that applies a fallible function to each item in the
+ /// iterator, stopping at the first error and returning that error.
+ ///
+ /// This can also be thought of as the fallible form of [`for_each()`]
+ /// or as the stateless version of [`try_fold()`].
+ ///
+ /// [`for_each()`]: #method.for_each
+ /// [`try_fold()`]: #method.try_fold
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(iterator_try_fold)]
+ /// use std::fs::rename;
+ /// use std::io::{stdout, Write};
+ /// use std::path::Path;
+ ///
+ /// let data = ["no_tea.txt", "stale_bread.json", "torrential_rain.png"];
+ ///
+ /// let res = data.iter().try_for_each(|x| writeln!(stdout(), "{}", x));
+ /// assert!(res.is_ok());
+ ///
+ /// let mut it = data.iter().cloned();
+ /// let res = it.try_for_each(|x| rename(x, Path::new(x).with_extension("old")));
+ /// assert!(res.is_err());
+ /// // It short-circuited, so the remaining items are still in the iterator:
+ /// assert_eq!(it.next(), Some("stale_bread.json"));
+ /// ```
+ #[inline]
+ #[unstable(feature = "iterator_try_fold", issue = "45594")]
+ fn try_for_each<F, R>(&mut self, mut f: F) -> R where
+ Self: Sized, F: FnMut(Self::Item) -> R, R: Try<Ok=()>
+ {
+ self.try_fold((), move |(), x| f(x))
+ }
+