File tree Expand file tree Collapse file tree 2 files changed +8
-17
lines changed
equinox-web-csharp/Domain Expand file tree Collapse file tree 2 files changed +8
-17
lines changed Original file line number Diff line number Diff line change 66using System ;
77using System . Collections . Generic ;
88using System . Threading . Tasks ;
9+ using OneOf ;
910
1011namespace TodoBackendTemplate
1112{
1213 public static class Aggregate
1314 {
1415 /// NB - these types and names reflect the actual storage formats and hence need to be versioned with care
15- public abstract class Event
16+ public abstract class Event : OneOfBase < Event . Happened , Event . Compacted >
1617 {
1718 public class Happened : Event
1819 {
@@ -43,21 +44,10 @@ public class State
4344
4445 internal State ( bool happened ) { Happened = happened ; }
4546
46- public static readonly State Initial = new State ( false ) ;
47-
48- static void Evolve ( State s , Event x )
49- {
50- switch ( x )
51- {
52- case Event . Happened e :
53- s . Happened = true ;
54- break ;
55- case Event . Compacted e :
56- s . Happened = e . Happened ;
57- break ;
58- default : throw new ArgumentOutOfRangeException ( nameof ( x ) , x , "invalid" ) ;
59- }
60- }
47+ static void Evolve ( State s , Event x ) =>
48+ x . Match (
49+ ( Happened _ ) => s . Happened = true ,
50+ ( Compacted e ) => s . Happened = e . Happened ) ;
6151
6252 public static State Fold ( State origin , IEnumerable < Event > xs )
6353 {
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <TargetFrameworks >netstandard2.0</TargetFrameworks >
5- <IsTestProject >false</ IsTestProject >
5+ <LangVersion >7.3</ LangVersion >
66 </PropertyGroup >
77
88 <ItemGroup >
99 <PackageReference Include =" Equinox" Version =" 1.0.3-rc1" />
1010 <PackageReference Include =" FSharp.Core" Version =" 4.5.4" />
1111 <PackageReference Include =" Newtonsoft.Json" Version =" 11.0.2" />
12+ <PackageReference Include =" OneOf" Version =" 2.1.127" />
1213 </ItemGroup >
1314
1415</Project >
You can’t perform that action at this time.
0 commit comments