def walk(<EOL>root_path: Union[str, pathlib.Path], top_down: bool = True<EOL>) -> Generator[<EOL>Tuple[pathlib.Path, Sequence[pathlib.Path], Sequence[pathlib.Path]], None, None<EOL>]:
root_path = pathlib.Path(root_path)<EOL>directory_paths, file_paths = [], []<EOL>for path in sorted(root_path.iterdir()):<EOL><INDENT>if path.is_dir():<EOL><INDENT>directory_paths.append(path)<EOL><DEDENT>else:<EOL><INDENT>file_paths.append(path)<EOL><DEDENT><DEDENT>if top_down:<EOL><INDENT>yield root_path, directory_paths, file_paths<EOL><DEDENT>for directory_path in directory_paths:<EOL><INDENT>yield from walk(directory_path, top_down=top_down)<EOL><DEDENT>if not top_down:<EOL><INDENT>yield root_path, directory_paths, file_paths<EOL><DEDENT>
Walks a directory tree.

Like :py:func:`os.walk` but yielding instances of :py:class:`pathlib.Path`
instead of strings.

:param root_path: foo
:param top_down: bar