RSCG – REslava.ResultFlow
| name | REslava.ResultFlow |
| nuget | https://www.nuget.org/packages/REslava.ResultFlow/ |
| link | https://github.com/reslava/nuget-package-reslava-result/ |
| author | Rafa Eslava |
Generates Mermaid flowchart diagrams at compile time from fluent Result pipeline methods — visualize functional code flows as diagrams
runtime overhead.
How to use
1. Decorate a fluent Result method with [ResultFlow]:
“`charp
[REslava.ResultFlow.ResultFlow]
public static Result
{
return Result
.Ensure(s => !string.IsNullOrWhiteSpace(s), new Error(“Input cannot be empty”))
.Map(s => s.ToUpper())
.Tap(s => Console.WriteLine($”Processed: {s}”))
.Ensure(s => int.TryParse(s, out _), new Error(“Input must be a valid integer”))
.Map(s => int.Parse(s));
}
“`
2. Access the generated Mermaid diagram as a compile-time const string:
“`charp
Console.WriteLine(Generated.ResultFlow.Helpers_Flows.GetValueFromConsole);
// outputs a Mermaid flowchart of the pipeline
“`
You can use for Auto-generating up-to-date Mermaid pipeline diagrams from functional Result code at compile time — ideal for documentation, design reviews, or visualizing complex flows without manual diagram maintenance.
This is how you can use REslava.ResultFlow .
The code that you start with is
<project sdk="Microsoft.NET.Sdk">
<propertygroup>
<outputtype>Exe</outputtype>
<targetframework>net10.0</targetframework>
<implicitusings>enable</implicitusings>
<nullable>enable</nullable>
</propertygroup>
<itemgroup>
<packagereference version="1.36.0" include="REslava.Result">
<packagereference version="1.36.0" include="REslava.Result.Analyzers">
<privateassets>all</privateassets>
<includeassets>runtime; build; native; contentfiles; analyzers; buildtransitive</includeassets>
</packagereference>
<packagereference version="1.36.0" include="REslava.ResultFlow">
<privateassets>all</privateassets>
<includeassets>runtime; build; native; contentfiles; analyzers; buildtransitive</includeassets>
</packagereference>
</packagereference>
<propertygroup>
<emitcompilergeneratedfiles>true</emitcompilergeneratedfiles>
<compilergeneratedfilesoutputpath>$(BaseIntermediateOutputPath)\GX</compilergeneratedfilesoutputpath>
</propertygroup>
</itemgroup>
The code that you will use is
// See https://aka.ms/new-console-template for more information
using ResultFlowGenerator;
Console.WriteLine("The mermaid is working!");
Console.WriteLine(Generated.ResultFlow.Helpers_Flows.GetValueFromConsole);
Console.WriteLine("Please enter an int");
var result = Helpers.GetValueFromConsole();
Console.WriteLine(result.IsSuccess
? $"You entered: {result.Value}"
: $"Failed to get a valid integer: {result.Errors.First().Message}");
using REslava.Result;
using REslava.Result.AdvancedPatterns;
using REslava.Result.Extensions;
using System;
using System.Collections.Generic;
namespace ResultFlowGenerator;
internal class Helpers
{
[REslava.ResultFlow.ResultFlow]
public static Result<int> GetValueFromConsole()
{
var value = Console.ReadLine() ?? "";
return Result<string>.Ok(value)
.Ensure(s => !string.IsNullOrWhiteSpace(s), new Error("Input cannot be empty"))
.Map(s => s.ToUpper())
.Tap(s => Console.WriteLine($"Processed: {s}"))
.TapOnFailure(e => Console.WriteLine($"Error: {e.Message}"))
.Ensure(s => int.TryParse(s, out _), new Error("Input must be a valid integer"))
.Map(s => int.Parse(s))
;
}
}
The code that is generated is
// <auto-generated>
// REslava.Result.Flow — auto-generated pipeline diagrams
// Do not edit manually.
namespace Generated.ResultFlow
{
internal static class Helpers_Flows
{
/// <summary>
/// Mermaid flow diagram for GetValueFromConsole.
/// Copy into any Mermaid renderer to visualize the pipeline.
/// </summary>
public const string GetValueFromConsole = @"
flowchart LR
N0_Ok[""Ok""]:::operation
N0_Ok --> N1_Ensure
N1_Ensure[""Ensure""]:::gatekeeper
N1_Ensure -->|pass| N2_Map
N1_Ensure -->|fail| F1[""Failure""]:::failure
N2_Map[""Map""]:::transform
N2_Map --> N3_Tap
N3_Tap[""Tap""]:::sideeffect
N3_Tap --> N4_TapOnFailure
N4_TapOnFailure[""TapOnFailure""]:::sideeffect
N4_TapOnFailure --> N5_Ensure
N5_Ensure[""Ensure""]:::gatekeeper
N5_Ensure -->|pass| N6_Map
N5_Ensure -->|fail| F5[""Failure""]:::failure
N6_Map[""Map""]:::transform
classDef operation fill:#e8f4f0,color:#1c7e6f
classDef gatekeeper fill:#e3e9fa,color:#3f5c9a
classDef failure fill:#f8e3e3,color:#b13e3e
classDef transform fill:#e3f0e8,color:#2f7a5c
classDef sideeffect fill:#fff4d9,color:#b8882c
";
}
}
// <auto-generated>
using System;
namespace REslava.ResultFlow
{
/// <summary>
/// Marks a method for automatic Mermaid flow diagram generation.
/// Apply to methods that use fluent Result<T> pipeline chains (Bind, Map, Ensure, Tap, Match).
/// The generated diagram constant is available at Generated.ResultFlow.{ClassName}_Flows.{MethodName}.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ResultFlowAttribute : Attribute { }
}
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/REslava.ResultFlow