Table of Contents

RecursiveSelectControl Enum

Definition

Namespace
Bodu.Collections.Extensions
Assembly
Bodu.Core.dll
Package
Bodu.Core 1.0.1
Source
RecursiveSelectControl.cs

Represents composable control flags for how an element is processed during recursive selection.

[Flags]
public enum RecursiveSelectControl
Attributes
Extension Methods

Fields

None = 0

No flags set: the current element is neither yielded nor recursed into.

Yield = 1

Primitive flag that includes the current element in the output sequence.

Recurse = 2

Primitive flag that requests recursion into the current element's children.

Skip = 4

Primitive flag that skips yielding the current element. Overrides Yield when both are set.

Break = 8

Primitive flag that stops iteration of the remaining siblings at the current recursion level.

Exit = 16

Primitive flag that terminates the entire recursive traversal immediately.

YieldOnly = 1

Yield the current element only, without recursing into children.

RecurseOnly = 2

Recurse into children without yielding the current element.

YieldAndRecurse = Yield | Recurse

Yield the current element and recurse into its children. This is the default behavior.

SkipOnly = 4

Skip yielding the current element and do not recurse.

SkipAndRecurse = Recurse | Skip

Skip yielding the current element, but still recurse into its children.

YieldAndBreak = Yield | Break

Yield the current element, then stop traversal at the current level (like a break).

SkipAndBreak = Skip | Break

Skip yielding the current element and stop traversal at the current level.

YieldAndExit = Yield | Exit

Yield the current element, then stop traversal completely across all levels.

SkipAndExit = Skip | Exit

Skip yielding the current element and stop traversal completely across all levels.

Examples

// Common input structure
var root = new[]
{
    new Node { Name = "A", Children = { new Node { Name = "B" }, new Node { Name = "C" } } },
    new Node { Name = "D" }
};
//
// RecursiveSelect using different control values

// YieldAndRecurse
var all = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.YieldAndRecurse);
// Output: A, B, C, D

// SkipOnly
var skip = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.SkipOnly);
// Output: (empty)

// YieldOnly
var yieldOnly = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.YieldOnly);
// Output: A, D

// RecurseOnly
var recurseOnly = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.RecurseOnly);
// Output: B, C

// SkipAndRecurse
var skipAndRecurse = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.SkipAndRecurse);
// Output: B, C

// YieldAndBreak
var yieldAndBreak = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.YieldAndBreak);
// Output: A

// SkipAndBreak
var skipAndBreak = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.SkipAndBreak);
// Output: (empty)

// YieldAndExit
var yieldAndExit = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.YieldAndExit);
// Output: A

// SkipAndExit
var skipAndExit = root.RecursiveSelect(
    n => n.Children,
    (n, i, d) => n.Name,
    n => RecursiveSelectControl.SkipAndExit);
// Output: (empty)

Remarks

This enum defines composable control flags that determine whether an element should be yielded, whether its children should be traversed, and whether traversal should stop after the current element. It is a genuine FlagsAttribute bitmask: the primitive flags Yield, Recurse, Skip, Break, and Exit may be combined with the bitwise-OR operator, and the named combinations below are provided for the common cases.

Break and Recurse are orthogonal and compose: Break stops iteration of the remaining siblings at the current level, whereas Recurse requests descent into the current element's children. When both are set, the current element's children are visited first and only then are the remaining siblings skipped.

Typical usage includes returning one of these values from a Func<T, RecursiveSelectControl> to control behavior dynamically within a recursive traversal method.

Behavior Matrix

CombinationYieldRecurseBreak LevelExit All
SkipOnlyNoNoNoNo
YieldOnlyYesNoNoNo
YieldAndRecurseYesYesNoNo
YieldAndBreakYesNoYesNo
YieldAndExitYesNoNoYes
RecurseOnlyNoYesNoNo
SkipAndRecurseNoYesNoNo
SkipAndBreakNoNoYesNo
SkipAndExitNoNoNoYes

Applies to

ProductVersions
.NET8, 10