diff options
| author | Jonas Hietala <tradet.h@gmail.com> | 2014-09-07 19:06:13 +0200 |
|---|---|---|
| committer | Jonas Hietala <tradet.h@gmail.com> | 2014-09-07 19:44:30 +0200 |
| commit | 248319a52e27f66396e178ace4fad41fc9c81d1e (patch) | |
| tree | 9c42ee7d854b5acae9cd133fab7bb04cd01d14e3 | |
| parent | 4067252def4251d7c2f4afc79ae1716093fe27ac (diff) | |
| download | rust-248319a52e27f66396e178ace4fad41fc9c81d1e.tar.gz rust-248319a52e27f66396e178ace4fad41fc9c81d1e.zip | |
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]
| -rw-r--r-- | src/libcore/iter.rs | 2 | ||||
| -rw-r--r-- | src/libcoretest/iter.rs | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index da7f026aed4..89b2f9cc853 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2185,7 +2185,7 @@ pub type Iterate<'a, T> = Unfold<'a, T, IterateState<'a, T>>; /// Creates a new iterator that produces an infinite sequence of /// repeated applications of the given function `f`. #[allow(visible_private_types)] -pub fn iterate<'a, T: Clone>(f: |T|: 'a -> T, seed: T) -> Iterate<'a, T> { +pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> { Unfold::new((f, Some(seed), true), |st| { let &(ref mut f, ref mut val, ref mut first) = st; if *first { diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 99ac7cfed02..9b703a18cae 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -839,7 +839,7 @@ fn test_min_max_result() { #[test] fn test_iterate() { - let mut it = iterate(|x| x * 2, 1u); + let mut it = iterate(1u, |x| x * 2); assert_eq!(it.next(), Some(1u)); assert_eq!(it.next(), Some(2u)); assert_eq!(it.next(), Some(4u)); |
