I have looked over im::vector::Vector - Rust twice.
Is there no 'join' function of sorts that does:
Vec<im::Vector<T>> -> im::Vector<T>
or
im::Vector<im::Vector<T>> -> im::Vector<T>
I have looked over im::vector::Vector - Rust twice.
Is there no 'join' function of sorts that does:
Vec<im::Vector<T>> -> im::Vector<T>
or
im::Vector<im::Vector<T>> -> im::Vector<T>
Vector
implements the Sum
trait, so you can use Iterator::sum
to join any iterator of Vectors. For example:
fn join<T: Clone>(v: Vec<im::Vector<T>>) -> im::Vector<T> {
v.into_iter().sum()
}
You could also write this using fold
:
fn join<T: Clone>(v: Vec<im::Vector<T>>) -> im::Vector<T> {
v.into_iter().fold(im::Vector::new(), |a, b| a + b)
}
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.