Skip to content

Instantly share code, notes, and snippets.

Ruben Bartelink bartelink

Block or report user

Report or block bartelink

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
bartelink /
Last active Aug 23, 2016 — forked from eulerfx/
The relationship between state machines and event sourcing

A state machine is defined as follows:

  • Input - a set of inputs
  • Output - a set of outputs
  • State - a set of states
  • S0 ∈ S - an initial state
  • T : Input * State -> Output * State - a transition function

If you model your services (aggregates, projections, process managers, sagas, whatever) as state machines, one issue to address is management of State. There must be a mechanism to provide State to the state machine, and to persist the resulting State for subsequent retrieval. One way to address this is by storing State in a key-value store. Another way is to use a SQL database. Yet another way is event sourcing. The benefit of event sourcing is that you never need to store State itself. Instead, you rely on the Output of a service to reconstitute state. In order to do that, the state machine transition function needs to be factored into two functions as follows:

View gist:8720521
public static TRes Match<T,TRes>(this FSharpOption<T> opt, Func<T,TRes> some, Func<TRes> none)
if (FSharpOption<T>.get_IsSome(opt))
return some.Invoke(opt.Value);
return none.Invoke();
View CompositeDataAttribute.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Xunit.Extensions;
namespace Prototypes.AutoFixture.Xunit.Extensions
public class CompositeDataAttribute : DataAttribute
View describe_AClass.cs
output of the row test below
describe AClass
describe many variations
A should equal A
C should equal A - [Failed]
//top level context to describe class
class describe_AClass
You can’t perform that action at this time.