-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
74 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace Fraktalio.FModel; | ||
|
||
internal static class InternalDeciderExtensions | ||
{ | ||
/// <summary> | ||
/// Combine [InternalDecider]s into one big [InternalDecider] | ||
/// | ||
/// Possible to use when: | ||
/// - [Ei] and [Ei2] have common superclass [Ei_SUPER] | ||
/// - [Eo] and [Eo2] have common superclass [Eo_SUPER] | ||
/// - [C] and [C2] have common superclass [C_SUPER] | ||
/// </summary> | ||
/// <param name="x">First Decider</param> | ||
/// <param name="y">Second Decider</param> | ||
/// <typeparam name="C">Command type of the first Decider</typeparam> | ||
/// <typeparam name="Si">Input_State type of the first Decider</typeparam> | ||
/// <typeparam name="So">Output_State type of the first Decider</typeparam> | ||
/// <typeparam name="Ei">Input_Event type of the first Decider</typeparam> | ||
/// <typeparam name="Eo">Output_Event type of the first Decider</typeparam> | ||
/// <typeparam name="C2">Command type of the second Decider</typeparam> | ||
/// <typeparam name="Si2">Input_State type of the second Decider</typeparam> | ||
/// <typeparam name="So2">Output_State type of the second Decider</typeparam> | ||
/// <typeparam name="Ei2">Input_Event type of the second Decider</typeparam> | ||
/// <typeparam name="Eo2">Output_Event type of the second Decider</typeparam> | ||
/// <typeparam name="C_SUPER">super type of the command types C and C2</typeparam> | ||
/// <typeparam name="Ei_SUPER">Super type of the Ei and Ei2 types</typeparam> | ||
/// <typeparam name="Eo_SUPER">super type of the Eo and Eo2 types</typeparam> | ||
/// <returns></returns> | ||
internal static InternalDecider<C_SUPER?, Tuple<Si, Si2>, Tuple<So, So2>, Ei_SUPER, Eo_SUPER?> Combine<C, Si, So, Ei, | ||
Eo, C2, Si2, So2, Ei2, Eo2, C_SUPER, Ei_SUPER, Eo_SUPER>( | ||
this InternalDecider<C?, Si, So, Ei?, Eo?> x, | ||
InternalDecider<C2?, Si2, So2, Ei2?, Eo2?> y) | ||
where C : class?, C_SUPER? | ||
where C2 : class, C_SUPER | ||
where Ei : class?, Ei_SUPER? | ||
where Eo : Eo_SUPER | ||
where Ei2 : class, Ei_SUPER | ||
where Eo2 : Eo_SUPER | ||
{ | ||
var deciderX = x.MapLeftOnCommand<C_SUPER?>(c => c as C) | ||
.MapLeftOnState<Tuple<Si, Si2>>(pair => pair.Item1) | ||
.DimapOnEvent<Ei_SUPER, Eo_SUPER?>(ei => ei as Ei, eo => eo); | ||
|
||
var deciderY = y.MapLeftOnCommand<C_SUPER?>(c => c as C2) | ||
.MapLeftOnState<Tuple<Si, Si2>>(pair => pair.Item2) | ||
.DimapOnEvent<Ei_SUPER, Eo_SUPER?>(ei => ei as Ei2, eo => eo); | ||
|
||
return deciderX.ProductOnState(deciderY); | ||
} | ||
|
||
internal static Decider<C, S, E> AsDecider<C, S, E>(this InternalDecider<C, S, S, E, E> internalDecider) => | ||
new(internalDecider.Decide, internalDecider.Evolve, internalDecider.InitialState); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/Fraktalio.FModel.Tests/Examples/Numbers/EvenNumberState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Fraktalio.FModel.Tests.Examples.Numbers; | ||
|
||
public sealed record EvenNumberState(Description Description, Number Value) : NumberState(Description, Value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
namespace Fraktalio.FModel.Tests.Examples.Numbers; | ||
|
||
public abstract record NumberState(Description Description, Number Value); | ||
|
||
public sealed record EvenNumberState(Description Description, Number Value) : NumberState(Description, Value); | ||
|
||
public sealed record OddNumberState(Description Description, Number Value) : NumberState(Description, Value); | ||
public abstract record NumberState(Description Description, Number Value); |
3 changes: 3 additions & 0 deletions
3
test/Fraktalio.FModel.Tests/Examples/Numbers/OddNumberState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Fraktalio.FModel.Tests.Examples.Numbers; | ||
|
||
public sealed record OddNumberState(Description Description, Number Value) : NumberState(Description, Value); |
2 changes: 1 addition & 1 deletion
2
...aktalio.FModel.Tests/DeciderExtensions.cs → ...del.Tests/Extensions/DeciderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...alio.FModel.Tests/EnumerableExtensions.cs → ....Tests/Extensions/EnumerableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../Fraktalio.FModel.Tests/SagaExtensions.cs → ...FModel.Tests/Extensions/SagaExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters