MCPcopy Create free account
hub / github.com/apache/arrow-rs / unary_mut

Method unary_mut

arrow-array/src/array/primitive_array.rs:949–959  ·  view source on GitHub ↗

Applies a unary and infallible function to the array in place if possible. # Buffer Reuse If the underlying buffers are not shared with other arrays, mutates the underlying buffer in place, without allocating. If the underlying buffer is shared, returns Err(self) # Null Handling See [`Self::unary`] for more information on null handling. # Example ```rust # use arrow_array::{Int32Array, typ

(self, op: F)

Source from the content-addressed store, hash-verified

947 /// assert_eq!(c, Int32Array::from(vec![Some(11), Some(15), None]));
948 /// ```
949 pub fn unary_mut<F>(self, op: F) -> Result<PrimitiveArray<T>, PrimitiveArray<T>>
950 where
951 F: Fn(T::Native) -> T::Native,
952 {
953 let mut builder = self.into_builder()?;
954 builder
955 .values_slice_mut()
956 .iter_mut()
957 .for_each(|v| *v = op(*v));
958 Ok(builder.finish())
959 }
960
961 /// Applies a unary fallible function to all valid values in a primitive
962 /// array, producing a new array of potentially different type.

Callers 2

unary_mutFunction · 0.45
test_unary_mutFunction · 0.45

Calls 3

into_builderMethod · 0.45
values_slice_mutMethod · 0.45
finishMethod · 0.45

Tested by 1

test_unary_mutFunction · 0.36