Skip to main content
added 19 characters in body
Source Link

Is this a satisfactory implementation of event sourcing using functional programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret cmd repo = cmd |> function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStorestore =  (Login loginPlan , Map.empty)  
 , Login   loginPlan)        ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||>       |> interpret (Deposit depositPlan)

Is this a satisfactory implementation of event sourcing using functional programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret repo = function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStore =  (Map.empty  , Login   loginPlan)   ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||> interpret

Is this a satisfactory implementation of event sourcing using functional programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret cmd repo = cmd |> function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let store =  (Login loginPlan , Map.empty)  
             ||> interpret
              |> interpret (Deposit depositPlan)
edited body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Is this a satisfactory implementation of Event Sourcingsourcing using Functional Programming?functional programming

Is this a satisfactory implementation of Event Sourcingevent sourcing using Functional Programmingfunctional programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret repo = function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStore =  (Map.empty  , Login   loginPlan)   ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||> interpret

Is this a satisfactory implementation of Event Sourcing using Functional Programming?

Is this a satisfactory implementation of Event Sourcing using Functional Programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret repo = function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStore =  (Map.empty  , Login   loginPlan)   ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||> interpret

Event sourcing using functional programming

Is this a satisfactory implementation of event sourcing using functional programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret repo = function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStore =  (Map.empty  , Login   loginPlan)   ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||> interpret
deleted 12 characters in body
Source Link

Is this a satisfactory implementation of Event Sourcing using Functional Programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repositoryrepo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repositoryrepo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret repo = function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStore =  (Map.empty  , Login   loginPlan)   ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||> interpret

Is this a satisfactory implementation of Event Sourcing using Functional Programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repository:Map<Event,_>) (plan:EventAggregate<'a>) =
    repository.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret repo = function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStore =  (Map.empty  , Login   loginPlan)   ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||> interpret

Is this a satisfactory implementation of Event Sourcing using Functional Programming?

module Account

(*Types*)
type EventAggregate<'Aggregate> = { Event:Event; Aggregate:'Aggregate }

and Command = 
    | Login      of EventAggregate<Account>
    | Deposit    of EventAggregate<Account>
    | Withdrawal of EventAggregate<Account>

and Event = 
    | LoggedIn  of Login
    | Deposited of decimal
    | Withdrew  of decimal

and AccountId = AccountId of string
and FirstName = FirstName of string
and LastName =  LastName  of string

and Login =   { UserId:string; Password:string }
and Account = {
    AccountId: AccountId
    FirstName: FirstName
    LastName:  LastName }

(*Functions*)
let appendTo (repo:Map<Event,_>) (plan:EventAggregate<'a>) =
    repo.Add (plan.Event , plan.Aggregate)

let getAccount login = {
    AccountId= AccountId "myAccountId"
    FirstName= FirstName "Scott"
    LastName= LastName   "Nimrod" }

let interpret repo = function
    | Login   v
    | Deposit v -> appendTo repo v      
    | _         -> repo

(*Client*)
let login = { UserId= "MyUserId"; Password= "MyPassword" }
let account = getAccount login

let loginPlan =    { Event=     LoggedIn login
                     Aggregate= account        }

let depositPlan =  { Event=     Deposited 100m
                     Aggregate= account        }

let firstStore =  (Map.empty  , Login   loginPlan)   ||> interpret
let secondStore = (firstStore , Deposit depositPlan) ||> interpret
Source Link
Loading