Skip to content

Commit e95ec2e

Browse files
committed
---
yaml --- r: 11238 b: refs/heads/master c: c21db3b h: refs/heads/master v: v3
1 parent 86681c7 commit e95ec2e

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-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: 4eeb706e84bc9e32aa5057e32d567ccab2c3cc2c
2+
refs/heads/master: c21db3bbc28c47e846783dedfe1eb1228f955f2b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/iter.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ fn repeat(times: uint, blk: fn()) {
8585
}
8686
}
8787

88+
fn min<A:copy,IA:iterable<A>>(self: IA) -> A {
89+
alt foldl(self, none) {|a, b|
90+
alt a {
91+
some(a) { some(math::min(a, b)) }
92+
none { some(b) }
93+
}
94+
} {
95+
some(val) { val }
96+
none { fail "min called on empty iterator" }
97+
}
98+
}
99+
100+
fn max<A:copy,IA:iterable<A>>(self: IA) -> A {
101+
alt foldl(self, none) {|a, b|
102+
alt a {
103+
some(a) { some(math::max(a, b)) }
104+
none { some(b) }
105+
}
106+
} {
107+
some(val) { val }
108+
none { fail "max called on empty iterator" }
109+
}
110+
}
88111

89112
#[test]
90113
fn test_enumerate() {
@@ -168,4 +191,26 @@ fn test_repeat() {
168191
assert c == [0u, 1u, 4u, 9u, 16u];
169192
}
170193

194+
#[test]
195+
fn test_min() {
196+
assert min([5, 4, 1, 2, 3]) == 1;
197+
}
171198

199+
#[test]
200+
#[should_fail]
201+
#[ignore(cfg(target_os = "win32"))]
202+
fn test_min_empty() {
203+
min::<int, [int]>([]);
204+
}
205+
206+
#[test]
207+
fn test_max() {
208+
assert max([1, 2, 4, 2, 3]) == 4;
209+
}
210+
211+
#[test]
212+
#[should_fail]
213+
#[ignore(cfg(target_os = "win32"))]
214+
fn test_max_empty() {
215+
max::<int, [int]>([]);
216+
}

0 commit comments

Comments
 (0)