libcore: Add vec any2 and all2 functions.
This commit is contained in:
@@ -507,6 +507,24 @@ fn any<T>(v: [T], f: block(T) -> bool) -> bool {
|
||||
ret false;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: any2
|
||||
|
||||
Return true if a predicate matches any elements in both vectors.
|
||||
|
||||
If the vectors contains no elements then false is returned.
|
||||
*/
|
||||
fn any2<T, U>(v0: [T], v1: [U], f: block(T, U) -> bool) -> bool {
|
||||
let v0_len = len(v0);
|
||||
let v1_len = len(v1);
|
||||
let i = 0u;
|
||||
while i < v0_len && i < v1_len {
|
||||
if f(v0[i], v1[i]) { ret true; };
|
||||
i += 1u;
|
||||
}
|
||||
ret false;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: all
|
||||
|
||||
@@ -519,6 +537,21 @@ fn all<T>(v: [T], f: block(T) -> bool) -> bool {
|
||||
ret true;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: all2
|
||||
|
||||
Return true if a predicate matches all elements in both vectors.
|
||||
|
||||
If the vectors are not the same size then false is returned.
|
||||
*/
|
||||
fn all2<T, U>(v0: [T], v1: [U], f: block(T, U) -> bool) -> bool {
|
||||
let v0_len = len(v0);
|
||||
if v0_len != len(v1) { ret false; }
|
||||
let i = 0u;
|
||||
while i < v0_len { if !f(v0[i], v1[i]) { ret false; }; i += 1u; }
|
||||
ret true;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: member
|
||||
|
||||
|
||||
Reference in New Issue
Block a user