@@ -532,17 +532,17 @@ impl<T> Transformed<T> {
532
532
}
533
533
}
534
534
535
- /// Transformation helper to process sequence of iterable tree nodes that are siblings.
535
+ /// Transformation helper to process a sequence of iterable tree nodes that are siblings.
536
536
pub trait TransformedIterator : Iterator {
537
537
/// Apples `f` to each item in this iterator
538
- ///
538
+ ///
539
539
/// Visits all items in the iterator unless
540
540
/// `f` returns an error or `f` returns TreeNodeRecursion::stop.
541
541
///
542
- /// # Returns
543
- /// Error if f returns an error
542
+ /// # Returns
543
+ /// Error if `f` returns an error
544
544
///
545
- /// Ok(Transformed) such that:
545
+ /// Ok(Transformed) such that:
546
546
/// 1. `transformed` is true if any return from `f` had transformed true
547
547
/// 2. `data` from the last invocation of `f`
548
548
/// 3. `tnr` from the last invocation of `f` or `Continue` if the iterator is empty
@@ -578,19 +578,35 @@ impl<I: Iterator> TransformedIterator for I {
578
578
}
579
579
}
580
580
581
- /// Transformation helper to process sequence of tree node containing expressions.
581
+ /// Transformation helper to process a heterogeneous sequence of tree node containing
582
+ /// expressions.
582
583
/// This macro is very similar to [TransformedIterator::map_until_stop_and_collect] to
583
- /// process nodes that are siblings, but it accepts an initial transformation and a
584
- /// sequence of pairs of an expression and its transformation.
584
+ /// process nodes that are siblings, but it accepts an initial transformation (`F0`) and
585
+ /// a sequence of pairs. Each pair is made of an expression (`EXPR`) and its
586
+ /// transformation (`F`).
587
+ ///
588
+ /// The macro builds up a tuple that contains `Transformed.data` result of `F0` as the
589
+ /// first element and further elements from the sequence of pairs. An element from a pair
590
+ /// is either the value of `EXPR` or the `Transformed.data` result of `F`, depending on
591
+ /// the `Transformed.tnr` result of previous `F`s (`F0` initially).
592
+ ///
593
+ /// # Returns
594
+ /// Error if any of the transformations returns an error
595
+ ///
596
+ /// Ok(Transformed<(data0, ..., dataN)>) such that:
597
+ /// 1. `transformed` is true if any of the transformations had transformed true
598
+ /// 2. `(data0, ..., dataN)`, where `data0` is the `Transformed.data` from `F0` and
599
+ /// `data1` ... `dataN` are from either `EXPR` or the `Transformed.data` of `F`
600
+ /// 3. `tnr` from `F0` or the last invocation of `F`
585
601
#[ macro_export]
586
602
macro_rules! map_until_stop_and_collect {
587
- ( $TRANSFORMED_EXPR_0 : expr, $( $EXPR: expr, $TRANSFORMED_EXPR : expr) ,* ) => { {
588
- $TRANSFORMED_EXPR_0 . and_then( |Transformed { data: data0, mut transformed, mut tnr } | {
589
- let data = (
603
+ ( $F0 : expr, $( $EXPR: expr, $F : expr) ,* ) => { {
604
+ $F0 . and_then( |Transformed { data: data0, mut transformed, mut tnr } | {
605
+ let all_datas = (
590
606
data0,
591
607
$(
592
608
if tnr == TreeNodeRecursion :: Continue || tnr == TreeNodeRecursion :: Jump {
593
- $TRANSFORMED_EXPR . map( |result| {
609
+ $F . map( |result| {
594
610
tnr = result. tnr;
595
611
transformed |= result. transformed;
596
612
result. data
0 commit comments