Last active
December 13, 2015 21:08
-
-
Save eulerfx/4975076 to your computer and use it in GitHub Desktop.
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
[<RequireQualifiedAccess>] | |
module Aggregate | |
type Aggregate<'TState, 'TCommand, 'TEvent> = { | |
zero : 'TState; | |
apply : 'TState -> 'TEvent -> 'TState; | |
exec : 'TState -> 'TCommand -> 'TEvent; | |
} | |
type Id = System.Guid | |
/// Creates a persistent command handler for an aggregate give load and commit functions. | |
let makeHandler (aggregate:Aggregate<'TState, 'TCommand, 'TEvent>) (load:Id -> 'TEvent seq, commit:Id * int -> 'TEvent -> unit) = | |
fun (id,version) command -> | |
let state = load id |> Seq.fold aggregate.apply aggregate.zero | |
let event = aggregate.exec state command | |
event |> commit (id,version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment