etseidl commented on code in PR #6252:
URL: https://github.com/apache/arrow-rs/pull/6252#discussion_r1725317053


##########
arrow-array/src/array/primitive_array.rs:
##########
@@ -1016,6 +1016,32 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
         PrimitiveArray::new(values, Some(nulls))
     }
 
+    /// Applies a unary infallible function to each value in an array, 
producing a
+    /// new primitive array.
+    ///
+    /// # Null Handling
+    ///
+    /// Applies the function for all values, including those on null slots. 
This
+    /// will often allow the compiler to generate faster vectorized code, but
+    /// requires that the operation must be infallible (not error/panic) for 
any
+    /// value of the corresponding type or this function may panic.
+    pub fn from_unary<U: ArrayAccessor, F>(left: U, mut op: F) -> Self
+    where
+        F: FnMut(U::Item) -> T::Native,
+    {
+        let nulls = left.logical_nulls();
+        let mut values: Vec<T::Native> = vec![T::Native::default(); 
left.len()];
+
+        for (i, val) in values.iter_mut().enumerate().take(left.len()) {

Review Comment:
   Thank you @jhorstmann! 🙏 I missed `spare_capacity_mut` in the docs. That 
seems quite handy.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to