Gorgon
Show / Hide Table of Contents

Class GorgonTreeLinqExtensions

LINQ extension methods for tree structures.

Inheritance
object
GorgonTreeLinqExtensions
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Collections
Assembly: Gorgon.Core.dll
Syntax
public static class GorgonTreeLinqExtensions

Methods

| Edit this page View Source

TraverseDepthFirst<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)

Function to flatten a tree of objects into a flat traversable list using a depth first approach.

Declaration
public static IEnumerable<T> TraverseDepthFirst<T>(this IEnumerable<T> children, Func<T, IEnumerable<T>> getChildren)
Parameters
Type Name Description
IEnumerable<T> children

The list of objects to evaluate.

Func<T, IEnumerable<T>> getChildren

The method to retrieve the next level of children.

Returns
Type Description
IEnumerable<T>

An enumerable containing the flattened list of objects.

Type Parameters
Name Description
T

The type of value in the tree.

Exceptions
Type Condition
ArgumentNullException

Thrown when the children parameter is null.

| Edit this page View Source

Traverse<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)

Function to flatten a tree of objects into a flat traversable list using a breadth first approach.

Declaration
public static IEnumerable<T> Traverse<T>(this IEnumerable<T> children, Func<T, IEnumerable<T>> getChildren)
Parameters
Type Name Description
IEnumerable<T> children

The list of objects to evaluate.

Func<T, IEnumerable<T>> getChildren

The method to retrieve the next level of children.

Returns
Type Description
IEnumerable<T>

An enumerable containing the flattened list of objects.

Type Parameters
Name Description
T

The type of value in the tree.

Exceptions
Type Condition
ArgumentNullException

Thrown when the children parameter is null.

  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author