Skip to content

Commit 10e6dff

Browse files
balootarcieri
andauthored
Add Array::map (#61)
Alternative to #60 Co-authored-by: Tony Arcieri <bascule@gmail.com>
1 parent f3cbc52 commit 10e6dff

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ where
229229
self.as_mut().iter_mut()
230230
}
231231

232+
/// Returns an array of the same size as `self`, with function `f` applied to each element in
233+
/// order.
234+
pub fn map<F, O>(self, f: F) -> Array<O, U>
235+
where
236+
F: FnMut(T) -> O,
237+
{
238+
self.into_iter().map(f).collect()
239+
}
240+
232241
/// Concatenates `self` with `other`.
233242
#[inline]
234243
pub fn concat<N>(self, other: Array<T, N>) -> Array<T, Sum<U, N>>

0 commit comments

Comments
 (0)