How can I chain operations on a Polars LazyFrame in Rust, similar to Python's .pipe() functionality?
I'm looking to refactor ~250 lines of operations into separate functions, but the Rust API doesn't seem to have an equivalent to Python's polars.LazyFrame.pipe().
use std::ops::Add;
use std::path::PathBuf;
use polars::lazy::dsl::*;
use polars::lazy::prelude::*;
use polars::prelude::*;
use tap::Pipe;
impl Reader {
// Private helper function - only visible within this module
fn select_path_columns_helper(lf: LazyFrame) -> LazyFrame {
lf.select([
col(mc::PATH_KEY),
col(mc::NODE_SEQUENCE),
// ... rest of your selection logic
])
}
// Public method that uses the private helper
pub fn paths_df(&mut self) -> Result<&DataFrame, PolarsError> {
if self.paths_df.is_none() {
let raw_df = self.read_raw_path_df()?;
let df = raw_df
.lazy()
.pipe(Self::select_path_columns_helper)
.collect()
.unwrap();
// ...
}
// ...
}
}