pub fn follow_cell_path(self, cell_path: &[PathMember]) -> Result<Value, ShellError> {
        let mut current = self;
        for member in cell_path {
            // FIXME: this uses a few extra clones for simplicity, but there may be a way
            // to traverse the path without them
            match member {
                PathMember::Int {
                    val: count,
                    span: origin_span,
                } => {
                    // Treat a numeric path member as `nth <val>`
                    match &mut current {
                        Value::List { vals: val, .. } => {
                            if let Some(item) = val.get(*count) {
                                current = item.clone();
                            } else {
                                return Err(ShellError::AccessBeyondEnd(val.len(), *origin_span));
                            }
                        }
                        x => {
                            return Err(ShellError::IncompatiblePathAccess(
                                format!("{}", x.get_type()),
                                *origin_span,
                            ))
                        }
                    }
                }
                PathMember::String {
                    val: column_name,
                    span: origin_span,
                } => match &mut current {
                    Value::Record { cols, vals, span } => {
                        let span = *span;
                        let mut found = false;
                        for col in cols.iter().zip(vals.iter()) {
                            if col.0 == column_name {
                                current = col.1.clone();
                                found = true;
                                break;
                            }
                        }

                        if !found {
                            return Err(ShellError::CantFindColumn(*origin_span, span));
                        }
                    }
                    Value::List { vals, span } => {
                        let mut output = vec![];
                        for val in vals {
                            output.push(val.clone().follow_cell_path(&[PathMember::String {
                                val: column_name.clone(),
                                span: *origin_span,
                            }])?);
                            // if let Value::Record { cols, vals, .. } = val {
                            //     for col in cols.iter().enumerate() {
                            //         if col.1 == column_name {
                            //             output.push(vals[col.0].clone());
                            //         }
                            //     }
                            // }
                        }

                        current = Value::List {
                            vals: output,
                            span: *span,
                        };
                    }
                    x => {
                        return Err(ShellError::IncompatiblePathAccess(
                            format!("{}", x.get_type()),
                            *origin_span,
                        ))
                    }
                },
            }
        }

        Ok(current)
    }
/// Follow a given column path into the value: for example accessing nth elements in a stream or list
Follow a given column path into the value: for example accessing nth elements in a stream or list
Follow a given column path into the value : for example accessing nth elements in a stream or list
pub fn follow_cell_path(self, cell_path: &[PathMember]) -> Result<Value, ShellError> {
        let mut current = self;
        for member in cell_path {
            // FIXME: this uses a few extra clones for simplicity, but there may be a way
            // to traverse the path without them
            match member {
                PathMember::Int {
                    val: count,
                    span: origin_span,
                } => {
                    // Treat a numeric path member as `nth <val>`
                    match &mut current {
                        Value::List { vals: val, .. } => {
                            if let Some(item) = val.get(*count) {
                                current = item.clone();
                            } else {
                                return Err(ShellError::AccessBeyondEnd(val.len(), *origin_span));
                            }
                        }
                        x => {
                            return Err(ShellError::IncompatiblePathAccess(
                                format!("{}", x.get_type()),
                                *origin_span,
                            ))
                        }
                    }
                }
                PathMember::String {
                    val: column_name,
                    span: origin_span,
                } => match &mut current {
                    Value::Record { cols, vals, span } => {
                        let span = *span;
                        let mut found = false;
                        for col in cols.iter().zip(vals.iter()) {
                            if col.0 == column_name {
                                current = col.1.clone();
                                found = true;
                                break;
                            }
                        }
                        if !found {
                            return Err(ShellError::CantFindColumn(*origin_span, span));
                        }
                    }
                    Value::List { vals, span } => {
                        let mut output = vec![];
                        for val in vals {
                            output.push(val.clone().follow_cell_path(&[PathMember::String {
                                val: column_name.clone(),
                                span: *origin_span,
                            }])?);
                            // if let Value::Record { cols, vals, .. } = val {
                            //     for col in cols.iter().enumerate() {
                            //         if col.1 == column_name {
                            //             output.push(vals[col.0].clone());
                            //         }
                            //     }
                            // }
                        }
                        current = Value::List {
                            vals: output,
                            span: *span,
                        };
                    }
                    x => {
                        return Err(ShellError::IncompatiblePathAccess(
                            format!("{}", x.get_type()),
                            *origin_span,
                        ))
                    }
                },
            }
        }
        Ok(current)
    }
pub fn follow_cell_path ( self , cell_path : & [ PathMember ] ) -> Result < Value , ShellError > { let mut current = self ; for member in cell_path { // FIXME: this uses a few extra clones for simplicity, but there may be a way // to traverse the path without them match member { PathMember :: Int { val : count , span : origin_span , } => { // Treat a numeric path member as `nth <val>` match & mut current { Value :: List { vals : val , .. } => { if let Some ( item ) = val . get ( * count ) { current = item . clone ( ) ; } else { return Err ( ShellError :: AccessBeyondEnd ( val . len ( ) , * origin_span ) ) ; } } x => { return Err ( ShellError :: IncompatiblePathAccess ( format ! ( " " x get_type ( ) ) , * origin_span , ) ) } } } PathMember :: String { val : column_name , span : origin_span , } => match & mut current { Value :: Record { cols , vals , span } => { let span = * span ; let mut found = false ; for col in cols . iter ( ) . zip ( vals . iter ( ) ) { if col . 0 == column_name { current = col . 1 . clone ( ) ; found = true ; break ; } } if ! found { return Err ( ShellError :: CantFindColumn ( * origin_span , span ) ) ; } } Value :: List { vals , span } => { let mut output = vec ! [ ] ; for val in vals { output . push ( val . clone ( ) . follow_cell_path ( & [ PathMember :: String { val : column_name . clone ( ) , span : * origin_span , } ] ) ? ) ; // if let Value::Record { cols, vals, .. } = val { //     for col in cols.iter().enumerate() { //         if col.1 == column_name { //             output.push(vals[col.0].clone()); //         } //     } // } } current = Value :: List { vals : output , span : * span , } ; } x => { return Err ( ShellError :: IncompatiblePathAccess ( format ! ( " " x get_type ( ) ) , * origin_span , ) ) } } , } } Ok ( current ) }
Follow a given column path into the value: for example accessing nth elements in a stream or list
Follow a given column path into the value : for example accessing nth elements in a stream or list
self
cell_path
&[PathMember]