Skip to content

Commit 02bdf90

Browse files
author
blake2-ppc
committed
extra: Use do instead of for in extra::iter
1 parent 6d7a0c8 commit 02bdf90

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/libextra/iter.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,9 @@ pub trait FromIter<T> {
7272
#[inline]
7373
pub fn any<T>(predicate: &fn(T) -> bool,
7474
iter: &fn(f: &fn(T) -> bool) -> bool) -> bool {
75-
for iter |x| {
76-
if predicate(x) {
77-
return true;
78-
}
75+
do iter |x| {
76+
predicate(x)
7977
}
80-
return false;
8178
}
8279

8380
/**
@@ -111,12 +108,14 @@ pub fn all<T>(predicate: &fn(T) -> bool,
111108
#[inline]
112109
pub fn find<T>(predicate: &fn(&T) -> bool,
113110
iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
114-
for iter |x| {
111+
let mut ret = None;
112+
do iter |x| {
115113
if predicate(&x) {
116-
return Some(x);
117-
}
118-
}
119-
None
114+
ret = Some(x);
115+
false
116+
} else { true }
117+
};
118+
ret
120119
}
121120

122121
/**
@@ -132,7 +131,7 @@ pub fn find<T>(predicate: &fn(&T) -> bool,
132131
#[inline]
133132
pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
134133
let mut result = None;
135-
for iter |x| {
134+
do iter |x| {
136135
match result {
137136
Some(ref mut y) => {
138137
if x > *y {
@@ -141,7 +140,8 @@ pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
141140
}
142141
None => result = Some(x)
143142
}
144-
}
143+
true
144+
};
145145
result
146146
}
147147

@@ -158,7 +158,7 @@ pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
158158
#[inline]
159159
pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
160160
let mut result = None;
161-
for iter |x| {
161+
do iter |x| {
162162
match result {
163163
Some(ref mut y) => {
164164
if x < *y {
@@ -167,7 +167,8 @@ pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
167167
}
168168
None => result = Some(x)
169169
}
170-
}
170+
true
171+
};
171172
result
172173
}
173174

@@ -183,9 +184,10 @@ pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
183184
#[inline]
184185
pub fn fold<T, U>(start: T, iter: &fn(f: &fn(U) -> bool) -> bool, f: &fn(&mut T, U)) -> T {
185186
let mut result = start;
186-
for iter |x| {
187+
do iter |x| {
187188
f(&mut result, x);
188-
}
189+
true
190+
};
189191
result
190192
}
191193

@@ -206,9 +208,10 @@ pub fn fold<T, U>(start: T, iter: &fn(f: &fn(U) -> bool) -> bool, f: &fn(&mut T,
206208
#[inline]
207209
pub fn fold_ref<T, U>(start: T, iter: &fn(f: &fn(&U) -> bool) -> bool, f: &fn(&mut T, &U)) -> T {
208210
let mut result = start;
209-
for iter |x| {
211+
do iter |x| {
210212
f(&mut result, x);
211-
}
213+
true
214+
};
212215
result
213216
}
214217

@@ -246,7 +249,7 @@ impl<T> FromIter<T> for ~[T]{
246249
#[inline]
247250
pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
248251
let mut v = ~[];
249-
for iter |x| { v.push(x) }
252+
do iter |x| { v.push(x); true };
250253
v
251254
}
252255
}

0 commit comments

Comments
 (0)