Skip to content

Commit c4c2db0

Browse files
committed
---
yaml --- r: 13743 b: refs/heads/master c: e56ba15 h: refs/heads/master i: 13741: b074ee5 13739: e35ee99 13735: 2101da1 13727: dc60629 v: v3
1 parent 9d5085a commit c4c2db0

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9f7e62ea209811fd1ca864498761e733f1c99298
2+
refs/heads/master: e56ba156e223e24025a743247610283cca49b30a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/iter-trait.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ impl extensions<A> of iter::base_iter<A> for IMPL_T<A> {
1616
}
1717
fn contains(x: A) -> bool { iter::contains(self, x) }
1818
fn count(x: A) -> uint { iter::count(self, x) }
19+
fn position(f: fn(A) -> bool) -> option<uint> {
20+
iter::position(self, f)
21+
}
1922
}
2023

2124
impl extensions<A:copy> for IMPL_T<A> {

trunk/src/libcore/iter.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint {
8585
}
8686
}
8787

88+
fn position<A,IA:base_iter<A>>(self: IA, f: fn(A) -> bool)
89+
-> option<uint> {
90+
let mut i = 0;
91+
for self.each {|a|
92+
if f(a) { ret some(i); }
93+
i += 1;
94+
}
95+
ret none;
96+
}
97+
98+
// note: 'rposition' would only make sense to provide with a bidirectional
99+
// iter interface, such as would provide "reach" in addition to "each". as is,
100+
// it would have to be implemented with foldr, which is too inefficient.
101+
88102
fn repeat(times: uint, blk: fn()) {
89103
let mut i = 0u;
90104
while i < times {

0 commit comments

Comments
 (0)