Enum TrackBehavior
- Namespace
- FunctionalDdd
- Assembly
- FunctionalDdd.RailwayOrientedProgramming.dll
Defines which railway track an operation runs on in Railway-Oriented Programming.
public enum TrackBehavior
- Extension Methods
Fields
Both = 2Operation executes on both success and failure tracks. Processes the Result regardless of its state.
Universal operations include:
Combine- Merge multiple results (aggregates both successes and failures)
Example:
firstName.Combine(lastName) // Combines results regardless of individual success/failure .Combine(email); // Aggregates all errors if any failFailure = 1Operation only executes when Result is a failure. Skipped if the Result is successful.
Failure track operations include:
TapOnFailure- Execute side effects on errorsMapOnFailure- Transform errorsRecoverOnFailure- Attempt recovery from errors
Example:
result.TapOnFailure(err => LogError(err)) // Only runs if result failed .MapOnFailure(err => AddContext(err)) // Only runs if still failed .RecoverOnFailure(() => GetDefault()); // Attempts recovery if failedSuccess = 0Operation only executes when Result is successful. Skipped if the Result is a failure.
Success track operations include:
Bind- Chain operations that can failMap- Transform success valuesTap- Execute side effects on successEnsure- Validate conditions (can switch to failure)
Example:
result.Bind(user => GetOrders(user)) // Only runs if result is success .Map(orders => orders.Count) // Only runs if Bind succeeded .Tap(count => Log(count)); // Only runs if Map succeededTerminal = 3Terminal operation that handles both tracks and exits the railway. Unwraps the Result and produces a final value.
Terminal operations include:
Match- Pattern match on success/failureMatchError- Pattern match on specific error types
Example:
result.Match( onSuccess: user => Ok(user), onFailure: error => BadRequest(error.Detail) ); // Exits the railway and returns final value
Remarks
In Railway-Oriented Programming, operations flow along two tracks:
- Success Track - Operations continue when everything works correctly
- Failure Track - Errors are captured and propagated automatically
Understanding track behavior is essential for composing railway-oriented pipelines. This enum makes the behavior explicit and enables tooling support.