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



##########
File path: arrow/src/datatypes/schema.rs
##########
@@ -87,6 +87,18 @@ impl Schema {
         Self { fields, metadata }
     }
 
+
+    /// Returns a new schema with only the specified columns in the new schema
+    /// This carries metadata from the parent schema over as well
+    pub fn project(&self, indices: impl IntoIterator<Item=usize>) -> 
Result<Schema> {
+        let mut new_fields = vec![];
+        for i in indices {
+            let f = self.fields[i].clone();
+            new_fields.push(f);
+        }

Review comment:
       I think the for loop thing is what one would write in other languages 
like C/C++, Java, go ,etc :) It is certainly what I was writing when I started 
learning rust.
   
   Then I realized that a big part of how rust avoids bounds checks while still 
being safe is by the use of the functional style (as in the compiler sets up 
the bound for `indicies` correctly once in the `into_iter()` and then doesn't 
need to do any checking on each iteration)




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