Skip to content

Commit 652e5bf

Browse files
committed
begin oneof
1 parent 8af6c1c commit 652e5bf

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

equinox-web-csharp/Domain/Aggregate.cs

100755100644
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Threading.Tasks;
9+
using OneOf;
910

1011
namespace 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
{

equinox-web-csharp/Domain/Domain.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
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>

0 commit comments

Comments
 (0)