Applies a unary infallible function to a primitive array, producing a new array of potentially different type. This is the fastest way to perform an operation on a primitive array when the benefits of a vectorized operation outweigh the cost of branching nulls and non-nulls. See also [`Self::unary_mut`] for in place modification. [`Self::try_unary`] for fallible operations. [`arrow::compute::bin
(&self, op: F)
| 893 | /// # } |
| 894 | /// ``` |
| 895 | pub fn unary<F, O>(&self, op: F) -> PrimitiveArray<O> |
| 896 | where |
| 897 | O: ArrowPrimitiveType, |
| 898 | F: Fn(T::Native) -> O::Native, |
| 899 | { |
| 900 | let nulls = self.nulls().cloned(); |
| 901 | let values = self.values().into_iter().map(|v| op(*v)); |
| 902 | let buffer: Vec<_> = values.collect(); |
| 903 | PrimitiveArray::new(buffer.into(), nulls) |
| 904 | } |
| 905 | |
| 906 | /// Applies a unary and infallible function to the array in place if possible. |
| 907 | /// |
no test coverage detected