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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -