Does Rust have a way to apply a function/method to each element in an array or vector? -
does rust language have way apply function each element in array/vector. know in python there map()
function performs task. in r there lapply()
, tapply()
, , apply()
functions this. wondering if there established way vectorize function in rust?
there's few subtleties here:
we have map, works on iterators. can:
some_vec.iter().map(|x| { })
however, iterators lazy, won't anything. can tack .collect() onto end make new vector new elements, if that's want.
the standard way without allocating use loop:
for in &vec {
if want functional style, can use forall method in itertools crate.
Comments
Post a Comment