Skip to content

Commit 248319a

Browse files
committed
Flip arguments to std::iter::iterate.
Breaks `iterate(f, seed)`, use `iterate(seed, f)` instead. The convention is to have the closure last. Closes #17066. [breaking-change]
1 parent 4067252 commit 248319a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/libcore/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ pub type Iterate<'a, T> = Unfold<'a, T, IterateState<'a, T>>;
21852185
/// Creates a new iterator that produces an infinite sequence of
21862186
/// repeated applications of the given function `f`.
21872187
#[allow(visible_private_types)]
2188-
pub fn iterate<'a, T: Clone>(f: |T|: 'a -> T, seed: T) -> Iterate<'a, T> {
2188+
pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> {
21892189
Unfold::new((f, Some(seed), true), |st| {
21902190
let &(ref mut f, ref mut val, ref mut first) = st;
21912191
if *first {

src/libcoretest/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ fn test_min_max_result() {
839839

840840
#[test]
841841
fn test_iterate() {
842-
let mut it = iterate(|x| x * 2, 1u);
842+
let mut it = iterate(1u, |x| x * 2);
843843
assert_eq!(it.next(), Some(1u));
844844
assert_eq!(it.next(), Some(2u));
845845
assert_eq!(it.next(), Some(4u));

0 commit comments

Comments
 (0)