alamb commented on a change in pull request #1296:
URL: https://github.com/apache/arrow-rs/pull/1296#discussion_r806260714



##########
File path: arrow/src/array/array_primitive.rs
##########
@@ -155,6 +155,16 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
         };
         PrimitiveArray::from(data)
     }
+
+    /// Returns an iterator that returns the values of `array.value(i)` for an 
iterator with each element `i`
+    pub fn take_iter<'a>(
+        &'a self,
+        indexes: impl Iterator<Item = Option<usize>> + 'a,
+    ) -> impl Iterator<Item = Option<T::Native>> + 'a {
+        indexes.map(|opt_index| {
+            opt_index.map(|index| unsafe { self.value_unchecked(index) })

Review comment:
       Nice 👍 
   
   Reading this, however, if someone passed in an interator that was out of 
bounds it will lead to undefined behavior; So I guess we would probably need to 
either validate every index or else mark the `take_iter` method as `unsafe` 
itself 🤔  which seems less than ideal.
   
   We can only avoid the bounds check if we knew the iterator came from a 
dictionary that had been previously validated.
   
   




-- 
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