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

Method from_unary

arrow-array/src/array/boolean_array.rs:274–284  ·  view source on GitHub ↗

Create a [`BooleanArray`] by evaluating the operation for each element of the provided array ``` # use arrow_array::{BooleanArray, Int32Array}; let array = Int32Array::from(vec![1, 2, 3, 4, 5]); let r = BooleanArray::from_unary(&array, |x| x > 2); assert_eq!(&r, &BooleanArray::from(vec![false, false, true, true, true])); ```

(left: T, mut op: F)

Source from the content-addressed store, hash-verified

272 /// assert_eq!(&r, &BooleanArray::from(vec![false, false, true, true, true]));
273 /// ```
274 pub fn from_unary<T: ArrayAccessor, F>(left: T, mut op: F) -> Self
275 where
276 F: FnMut(T::Item) -> bool,
277 {
278 let nulls = left.logical_nulls();
279 let values = BooleanBuffer::collect_bool(left.len(), |i| unsafe {
280 // SAFETY: i in range 0..len
281 op(left.value_unchecked(i))
282 });
283 Self::new(values, nulls)
284 }
285
286 /// Create a [`BooleanArray`] by evaluating the binary operation for
287 /// each element of the provided arrays

Callers

nothing calls this directly

Calls 4

collect_boolFunction · 0.85
logical_nullsMethod · 0.45
lenMethod · 0.45
value_uncheckedMethod · 0.45

Tested by

no test coverage detected