< Summary

Class:Towel.Steppable
Assembly:Towel
File(s):File 1: /home/runner/work/Towel/Towel/Sources/Towel/Step.cs
Covered lines:9
Uncovered lines:0
Coverable lines:9
Total lines:64
Line coverage:100% (9 of 9)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
File 1: Stepper(...)50%2100%
File 1: Stepper(...)100%1100%
File 1: StepperBreak(...)50%2100%

File(s)

/home/runner/work/Towel/Towel/Sources/Towel/Step.cs

#LineLine coverage
 1namespace Towel;
 2
 3/// <summary>Status of iteration.</summary>
 4public enum StepStatus
 5{
 6  /// <summary>Stepper was not broken.</summary>
 7  Continue = 0,
 8  /// <summary>Stepper was broken.</summary>
 9  Break = 1,
 10}
 11
 12/// <summary>Polymorphism base for all data structures in the Towel framework.</summary>
 13/// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 14public interface ISteppable<T>
 15{
 16  #region Methods
 17
 18  /// <summary>Traverses values and invokes a function on every <typeparamref name="T"/> value.</summary>
 19  /// <typeparam name="TStep">The type of function to invoke on every <typeparamref name="T"/> value.</typeparam>
 20  /// <param name="step">The function to invoke on every <typeparamref name="T"/> value.</param>
 21  /// <returns>The status of the traversal.</returns>
 22  StepStatus StepperBreak<TStep>(TStep step = default)
 23    where TStep : struct, IFunc<T, StepStatus>;
 24
 25  #endregion
 26}
 27
 28/// <summary>Static members for <see cref="ISteppable{T}"/>.</summary>
 29public static class Steppable
 30{
 31  #region Extension Methods
 32
 33  /// <summary>Traverses values and invokes a function on every <typeparamref name="T"/> value.</summary>
 34  /// <typeparam name="T">The type of value to traverse.</typeparam>
 35  /// <param name="steppable">The values to step though.</param>
 36  /// <param name="step">The function to invoke on every <typeparamref name="T"/> value.</param>
 37  public static void Stepper<T>(this ISteppable<T> steppable, Action<T> step)
 499638  {
 499639    if (step is null) throw new ArgumentNullException(nameof(step));
 499640    steppable.Stepper<T, SAction<T>>(step);
 499641  }
 42
 43  /// <summary>Traverses values and invokes a function on every <typeparamref name="T"/> value.</summary>
 44  /// <typeparam name="T">The type of value to traverse.</typeparam>
 45  /// <typeparam name="TStep">The type of function to invoke on every <typeparamref name="T"/> value.</typeparam>
 46  /// <param name="steppable">The values to step though.</param>
 47  /// <param name="step">The function to invoke on every <typeparamref name="T"/> value.</param>
 48  public static void Stepper<T, TStep>(this ISteppable<T> steppable, TStep step = default)
 49    where TStep : struct, IAction<T> =>
 500850    steppable.StepperBreak<StepBreakFromAction<T, TStep>>(step);
 51
 52  /// <summary>Traverses values and invokes a function on every <typeparamref name="T"/> value.</summary>
 53  /// <typeparam name="T">The type of value to traverse.</typeparam>
 54  /// <param name="steppable">The values to step though.</param>
 55  /// <param name="step">>The function to invoke on every <typeparamref name="T"/> value.</param>
 56  /// <returns>The status of the traversal.</returns>
 57  public static StepStatus StepperBreak<T>(this ISteppable<T> steppable, Func<T, StepStatus> step)
 558  {
 559    if (step is null) throw new ArgumentNullException(nameof(step));
 560    return steppable.StepperBreak<SFunc<T, StepStatus>>(step);
 561  }
 62
 63  #endregion
 64}