Repository: rayon-rs/rayon (Rust)

Issue:
Rename repeatn
As of rust 1.82.0, The standard library includes the function repeat_n (https://doc.rust-lang.org/std/iter/fn.repeat_n.html) which takes an element and a usize and constructs the iterator which repeats the element `n` times.

Rayon includes the same function (https://docs.rs/rayon/latest/rayon/iter/fn.repeatn.html) but uses a slightly different name (repeatn instead of repeat_n) .

Clearly not a high priority but it would be nice to fix this so the names match up.


Discussion:
Yeah, I agree that we should match `repeat_n`, deprecating `repeatn`.



Patch:
diff --git a/src/iter/mod.rs b/src/iter/mod.rs
index c7e3a0d99..ead11fb32 100644
--- a/src/iter/mod.rs
+++ b/src/iter/mod.rs
@@ -190,7 +190,7 @@ pub use self::{
     panic_fuse::PanicFuse,
     par_bridge::{IterBridge, ParallelBridge},
     positions::Positions,
-    repeat::{repeat, repeatn, Repeat, RepeatN},
+    repeat::{repeat, repeat_n, Repeat, RepeatN},
     rev::Rev,
     skip::Skip,
     skip_any::SkipAny,
@@ -210,6 +210,9 @@ pub use self::{
     zip_eq::ZipEq,
 };
 
+#[allow(deprecated)]
+pub use repeat::repeatn;
+
 /// `IntoParallelIterator` implements the conversion to a [`ParallelIterator`].
 ///
 /// By implementing `IntoParallelIterator` for a type, you define how it will
diff --git a/src/iter/repeat.rs b/src/iter/repeat.rs
index f8843edc8..5a6120068 100644
--- a/src/iter/repeat.rs
+++ b/src/iter/repeat.rs
@@ -12,7 +12,7 @@ pub struct Repeat<T: Clone + Send> {
 /// cloning it). Note that this iterator has "infinite" length, so
 /// typically you would want to use `zip` or `take` or some other
 /// means to shorten it, or consider using
-/// [the `repeatn()` function](fn.repeatn.html) instead.
+/// [the `repeat_n()` function](fn.repeat_n.html) instead.
 ///
 /// # Examples
 ///
@@ -36,7 +36,7 @@ where
     /// The resulting `RepeatN` is an `IndexedParallelIterator`, allowing
     /// more functionality than `Repeat` alone.
     pub fn take(self, n: usize) -> RepeatN<T> {
-        repeatn(self.element, n)
+        repeat_n(self.element, n)
     }
 
     /// Iterates tuples, repeating the element with items from another
@@ -97,7 +97,7 @@ impl<T: Clone + Send> UnindexedProducer for RepeatProducer<T> {
     }
 }
 
-/// Iterator adaptor for [the `repeatn()` function](fn.repeatn.html).
+/// Iterator adaptor for [the `repeat_n()` function](fn.repeat_n.html).
 #[derive(Debug, Clone)]
 pub struct RepeatN<T: Clone + Send> {
     element: T,
@@ -111,10 +111,22 @@ pub struct RepeatN<T: Clone + Send> {
 ///
 /// ```
 /// use rayon::prelude::*;
-/// use rayon::iter::repeatn;
-/// let x: Vec<(i32, i32)> = repeatn(22, 3).zip(0..3).collect();
+/// use rayon::iter::repeat_n;
+/// let x: Vec<(i32, i32)> = repeat_n(22, 3).zip(0..3).collect();
 /// assert_eq!(x, vec![(22, 0), (22, 1), (22, 2)]);
 /// ```
+pub fn repeat_n<T: Clone + Send>(elt: T, n: usize) -> RepeatN<T> {
+    RepeatN {
+        element: elt,
+        count: n,
+    }
+}
+
+/// Creates a parallel iterator that produces `n` repeats of `elt`
+/// (by cloning it).
+///
+/// Deprecated in favor of [`repeat_n`] for consistency with the standard library.
+#[deprecated(note = "use `repeat_n`")]
 pub fn repeatn<T: Clone + Send>(elt: T, n: usize) -> RepeatN<T> {
     RepeatN {
         element: elt,


Test patch:
diff --git a/src/iter/test.rs b/src/iter/test.rs
index 08fd57a4c..3bd957e34 100644
--- a/src/iter/test.rs
+++ b/src/iter/test.rs
@@ -2183,9 +2183,9 @@ fn check_repeat_zip() {
 }
 
 #[test]
-fn check_repeatn_zip_left() {
+fn check_repeat_n_zip_left() {
     let v = vec![4, 4, 4, 4];
-    let mut fours: Vec<_> = repeatn(4, usize::MAX).zip(v).collect();
+    let mut fours: Vec<_> = repeat_n(4, usize::MAX).zip(v).collect();
     assert_eq!(fours.len(), 4);
     while let Some(item) = fours.pop() {
         assert_eq!(item, (4, 4));
@@ -2193,9 +2193,9 @@ fn check_repeatn_zip_left() {
 }
 
 #[test]
-fn check_repeatn_zip_right() {
+fn check_repeat_n_zip_right() {
     let v = vec![4, 4, 4, 4];
-    let mut fours: Vec<_> = v.into_par_iter().zip(repeatn(4, usize::MAX)).collect();
+    let mut fours: Vec<_> = v.into_par_iter().zip(repeat_n(4, usize::MAX)).collect();
     assert_eq!(fours.len(), 4);
     while let Some(item) = fours.pop() {
         assert_eq!(item, (4, 4));
diff --git a/tests/clones.rs b/tests/clones.rs
index 9ffa1d131..1782fe2ad 100644
--- a/tests/clones.rs
+++ b/tests/clones.rs
@@ -196,7 +196,7 @@ fn clone_once() {
 fn clone_repeat() {
     let x: Option<i32> = None;
     check(rayon::iter::repeat(x).while_some());
-    check(rayon::iter::repeatn(x, 1000));
+    check(rayon::iter::repeat_n(x, 1000));
 }
 
 #[test]
diff --git a/tests/debug.rs b/tests/debug.rs
index 97d89cd6a..12fbf05ac 100644
--- a/tests/debug.rs
+++ b/tests/debug.rs
@@ -207,7 +207,7 @@ fn debug_once() {
 fn debug_repeat() {
     let x: Option<i32> = None;
     check(rayon::iter::repeat(x));
-    check(rayon::iter::repeatn(x, 10));
+    check(rayon::iter::repeat_n(x, 10));
 }
 
 #[test]
diff --git a/tests/producer_split_at.rs b/tests/producer_split_at.rs
index 574fec187..ab2c4bc35 100644
--- a/tests/producer_split_at.rs
+++ b/tests/producer_split_at.rs
@@ -142,9 +142,9 @@ fn range_inclusive() {
 }
 
 #[test]
-fn repeatn() {
+fn repeat_n() {
     let v: Vec<_> = std::iter::repeat(1).take(5).collect();
-    check(&v, || rayon::iter::repeatn(1, 5));
+    check(&v, || rayon::iter::repeat_n(1, 5));
 }
 
 #[test]