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

Method from_unary

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

Applies a unary infallible function to each value in an array, producing a new primitive array. # Null Handling See [`Self::unary`] for more information on null handling. # Example: create an [`Int16Array`] from an [`ArrayAccessor`] with item type `&[u8]` ``` use arrow_array::{Array, FixedSizeBinaryArray, Int16Array}; let input_arg = vec![ vec![1, 0], vec![2, 0], vec![3, 0] ]; let arr = FixedSi

(left: U, mut op: F)

Source from the content-addressed store, hash-verified

1097 /// assert_eq!(c, Int16Array::from(vec![Some(1i16), Some(2i16), Some(3i16)]));
1098 /// ```
1099 pub fn from_unary<U: ArrayAccessor, F>(left: U, mut op: F) -> Self
1100 where
1101 F: FnMut(U::Item) -> T::Native,
1102 {
1103 let nulls = left.logical_nulls();
1104 let buffer: Vec<_> = (0..left.len())
1105 // SAFETY: i in range 0..left.len()
1106 .map(|i| op(unsafe { left.value_unchecked(i) }))
1107 .collect();
1108 PrimitiveArray::new(buffer.into(), nulls)
1109 }
1110
1111 /// Returns a `PrimitiveBuilder` for this array, suitable for mutating values
1112 /// in place.

Callers

nothing calls this directly

Calls 4

collectMethod · 0.80
logical_nullsMethod · 0.45
lenMethod · 0.45
value_uncheckedMethod · 0.45

Tested by

no test coverage detected