public static IVirtualForest <T> Prune <T>( this IVirtualForest <T> forest, Func <T, bool> predicate, PruneOption pruneOption) { PruneTreeWalker <T> walker = new PruneTreeWalker <T>( forest.TreeWalker, predicate, pruneOption); switch (pruneOption) { case PruneOption.PruneDescendants: return (forest .ShallowCopy( walker, roots => roots)); case PruneOption.PruneTree: return (forest .ShallowCopy( walker, roots => roots.Where(x => !predicate(x)))); default: throw new NotImplementedException("Whoops! Somebody introduced a new pruning option and forgot to update the switch block."); } }
public static IVirtualForest <T> Siblings <T>(this IVirtualForest <T> forest) { return (forest .ShallowCopy(roots => roots .SelectMany(forest.TreeWalker.GetSiblings))); }
public static IVirtualForest <T> PrecedingSiblings <T>(this IVirtualForest <T> forest) { return (forest .ShallowCopy(roots => roots .SelectMany(y => forest .TreeWalker .GetPrecedingSiblings(y, forest.Comparer)))); }
public static IVirtualForest <T> Siblings <T>(this IVirtualForest <T> forest, IEqualityComparer <T> comparer) { return (forest .ShallowCopy(roots => roots .SelectMany(x => forest .TreeWalker .GetSiblings(x, comparer)))); }
public static IVirtualForest <T> FollowingSiblingsAndSelf <T>(this IVirtualForest <T> forest) { return (forest .ShallowCopy(roots => roots .SelectMany(y => forest .TreeWalker .GetFollowingSiblingsAndSelf(y, forest.Comparer)))); }
// TODO: what happens when two roots are siblings (have the same parent). // Should I deduplicate the results? If so how? Using an IEqualityComparer might cause // issues. public static IVirtualForest <T> Parents <T>(this IVirtualForest <T> forest) { return (forest .ShallowCopy(roots => roots .SelectMany(x => forest .TreeWalker .GetAncestors(x) .Take(1)))); }
public static IVirtualForest <T> Level <T>( this IVirtualForest <T> forest, int depth) { return (forest .ShallowCopy(roots => roots .SelectMany(x => forest .TreeWalker .GetLevel(x, depth)))); }
public static IVirtualForest <T> Internals <T>(this IVirtualForest <T> forest) { InternalsTreeWalker <T> walker = new InternalsTreeWalker <T>(forest.TreeWalker); return (forest .ShallowCopy( walker, roots => roots .Where(x => forest .TreeWalker .HasChildren(x)))); }
public static IVirtualForest <T> Where <T>( this IVirtualForest <T> forest, Func <T, bool> predicate) { WhereTreeWalker <T> walker = new WhereTreeWalker <T>(forest.TreeWalker, predicate); return (forest .ShallowCopy( walker, roots => roots .SelectMany(x => predicate(x) ? new T[] { x } : walker.GetDescendants(x, predicate)))); }
public static IVirtualForest <T> Descendants <T>( this IVirtualForest <T> forest, Func <T, bool> predicate) { return(forest.ShallowCopy(roots => forest.TreeWalker.GetDescendants(roots, predicate))); }
public static IVirtualForest <T> Children <T>( this IVirtualForest <T> forest, T key) { return(forest.ShallowCopy(roots => roots.Where(y => forest.Comparer.Equals(key, y)))); }
public static IVirtualForest <T> Children <T>( this IVirtualForest <T> forest, Func <T, bool> predicate) { return(forest.ShallowCopy(roots => forest.TreeWalker.GetChildren(roots, predicate))); }
public static IVirtualForest <T> Children <T>(this IVirtualForest <T> forest) { return(forest.ShallowCopy(roots => roots.SelectMany(forest.TreeWalker.GetChildren))); }
public static IVirtualForest <T> ChildAt <T>( this IVirtualForest <T> forest, int index) { return(forest.ShallowCopy(roots => forest.TreeWalker.GetChildAt(roots, index))); }
public static IVirtualForest <T> Descendants <T>( this IVirtualForest <T> forest, T key) { return(forest.ShallowCopy(roots => forest.TreeWalker.GetDescendants(roots, key, forest.Comparer))); }