Skip to content

Commit

Permalink
Refine documentation for Transformed::{update,map,transform})_data (a…
Browse files Browse the repository at this point in the history
…pache#10355)

* Refine documentation for `Transformed::{update,map,transform})_data`

* Update datafusion/common/src/tree_node.rs

Co-authored-by: comphead <[email protected]>

---------

Co-authored-by: comphead <[email protected]>
  • Loading branch information
alamb and comphead authored May 3, 2024
1 parent b21bf9e commit 6480020
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions datafusion/common/src/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,17 +625,23 @@ impl<T> Transformed<T> {
Self::new(data, false, TreeNodeRecursion::Continue)
}

/// Applies the given `f` to the data of this [`Transformed`] object.
/// Applies an infallible `f` to the data of this [`Transformed`] object,
/// without modifying the `transformed` flag.
pub fn update_data<U, F: FnOnce(T) -> U>(self, f: F) -> Transformed<U> {
Transformed::new(f(self.data), self.transformed, self.tnr)
}

/// Maps the data of [`Transformed`] object to the result of the given `f`.
/// Applies a fallible `f` (returns `Result`) to the data of this
/// [`Transformed`] object, without modifying the `transformed` flag.
pub fn map_data<U, F: FnOnce(T) -> Result<U>>(self, f: F) -> Result<Transformed<U>> {
f(self.data).map(|data| Transformed::new(data, self.transformed, self.tnr))
}

/// Maps the [`Transformed`] object to the result of the given `f`.
/// Applies a fallible transforming `f` to the data of this [`Transformed`]
/// object.
///
/// The returned `Transformed` object has the `transformed` flag set if either
/// `self` or the return value of `f` have the `transformed` flag set.
pub fn transform_data<U, F: FnOnce(T) -> Result<Transformed<U>>>(
self,
f: F,
Expand Down

0 comments on commit 6480020

Please sign in to comment.