pub fn walk_with_behavior(
        self,
        behavior: impl Into<WalkBehavior>,
    ) -> impl 'static + FileIterator<Entry = GlobEntry, Residue = TreeEntry> {
        self.anchor
            .walk_with_behavior(behavior)
            .filter_map_tree(move |cancellation, separation| {
                use itertools::{
                    EitherOrBoth::{Both, Left, Right},
                    Position::{First, Last, Middle, Only},
                };

                let filtrate = match separation.filtrate() {
                    Some(filtrate) => match filtrate.transpose() {
                        Ok(filtrate) => filtrate,
                        Err(error) => {
                            return Separation::from(error.map(Err));
                        }
                    },
                    // `Path::walk_with_behavior` yields no residue.
                    _ => unreachable!(),
                };
                let entry = filtrate.as_ref();
                let (_, path) = entry.root_relative_paths();
                let depth = entry.depth().saturating_sub(1);
                for (position, candidate) in path
                    .components()
                    .filter_map(|component| match component {
                        Component::Normal(component) => Some(CandidatePath::from(component)),
                        Component::Prefix(prefix) => Some(CandidatePath::from(prefix.as_os_str())),
                        _ => None,
                    })
                    .skip(depth)
                    .zip_longest(self.program.components.iter().skip(depth))
                    .with_position()
                {
                    match (position, candidate) {
                        (First | Middle, Both(candidate, program)) => {
                            if !program.is_match(candidate.as_ref()) {
                                // Do not walk directories that do not match the corresponding
                                // component program.
                                return filtrate.filter_tree(cancellation).into();
                            }
                        }
                        (Last | Only, Both(candidate, program)) => {
                            return if program.is_match(candidate.as_ref()) {
                                let candidate = CandidatePath::from(path);
                                if let Some(matched) = self
                                    .program
                                    .complete
                                    .captures(candidate.as_ref())
                                    .map(MatchedText::from)
                                    .map(MatchedText::into_owned)
                                {
                                    filtrate
                                        .map(|entry| Ok(GlobEntry { entry, matched }))
                                        .into()
                                } else {
                                    filtrate.filter_node().into()
                                }
                            } else {
                                // Do not walk directories that do not match the corresponding
                                // component program.
                                filtrate.filter_tree(cancellation).into()
                            };
                        }
                        (_, Left(_candidate)) => {
                            let candidate = CandidatePath::from(path);
                            return if let Some(matched) = self
                                .program
                                .complete
                                .captures(candidate.as_ref())
                                .map(MatchedText::from)
                                .map(MatchedText::into_owned)
                            {
                                filtrate
                                    .map(|entry| Ok(GlobEntry { entry, matched }))
                                    .into()
                            } else {
                                filtrate.filter_node().into()
                            };
                        }
                        (_, Right(_program)) => {
                            return filtrate.filter_node().into();
                        }
                    }
                }
                // If the component loop is not entered, then check for a match. This may
                // indicate that the `Glob` is empty and a single invariant path
                // may be matched.
                let candidate = CandidatePath::from(path);
                if let Some(matched) = self
                    .program
                    .complete
                    .captures(candidate.as_ref())
                    .map(MatchedText::from)
                    .map(MatchedText::into_owned)
                {
                    return filtrate
                        .map(|entry| Ok(GlobEntry { entry, matched }))
                        .into();
                }
                filtrate.filter_node().into()
            })
    }
Converts a walker into an iterator over matching files in its directory
tree.

See [`Glob::walk_with_behavior`].

[`Glob::walk_with_behavior`]: crate::Glob::walk_with_behavior
crates/turborepo-wax/src/walk/glob.rs