Skip to content

Commit

Permalink
begin oneof
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Jan 17, 2019
1 parent 317532d commit 40ced17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
22 changes: 6 additions & 16 deletions equinox-web-csharp/Domain/Aggregate.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OneOf;

namespace TodoBackendTemplate
{
public static class Aggregate
{
/// NB - these types and names reflect the actual storage formats and hence need to be versioned with care
public abstract class Event
public abstract class Event : OneOfBase<Event.Happened, Event.Compacted>
{
public class Happened : Event
{
Expand Down Expand Up @@ -43,21 +44,10 @@ public class State

internal State(bool happened) { Happened = happened; }

public static readonly State Initial = new State(false);

static void Evolve(State s, Event x)
{
switch (x)
{
case Event.Happened e:
s.Happened = true;
break;
case Event.Compacted e:
s.Happened = e.Happened;
break;
default: throw new ArgumentOutOfRangeException(nameof(x), x, "invalid");
}
}
static void Evolve(State s, Event x) =>
x.Match(
(Happened _) => s.Happened = true,
(Compacted e) => s.Happened = e.Happened);

public static State Fold(State origin, IEnumerable<Event> xs)
{
Expand Down
3 changes: 2 additions & 1 deletion equinox-web-csharp/Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Equinox" Version="1.0.3" />
<PackageReference Include="FSharp.Core" Version="4.5.4" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="OneOf" Version="2.1.127" />
</ItemGroup>

</Project>

0 comments on commit 40ced17

Please sign in to comment.