rewrite the resolution infrastructure; but it's still grody

This commit is contained in:
Niko Matsakis
2012-04-20 15:46:57 -07:00
parent 68f8812511
commit 0d3658bb43
4 changed files with 230 additions and 159 deletions

View File

@@ -142,7 +142,9 @@ checking for overflow:
assert incd == [2u, 3u, 4u];
}
"]
fn map<T,U:copy,V:copy>(ts: [T], op: fn(T) -> result<V,U>) -> result<[V],U> {
fn map<T,U:copy,V:copy>(
ts: [T], op: fn(T) -> result<V,U>) -> result<[V],U> {
let mut vs: [V] = [];
vec::reserve(vs, vec::len(ts));
for vec::each(ts) {|t|
@@ -154,6 +156,20 @@ fn map<T,U:copy,V:copy>(ts: [T], op: fn(T) -> result<V,U>) -> result<[V],U> {
ret ok(vs);
}
fn map_opt<T,U:copy,V:copy>(
o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> {
alt o_t {
none { ok(none) }
some(t) {
alt op(t) {
ok(v) { ok(some(v)) }
err(e) { err(e) }
}
}
}
}
#[doc = "Same as map, but it operates over two parallel vectors.
A precondition is used here to ensure that the vectors are the same