Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
[<RequireQualifiedAccess>]
module InventoryItem
type State = {
isActive : bool;
}
with static member Zero = { isActive = false }
type Command =
| Create of string
| Deactivate
| Rename of string
| CheckInItems of int
| RemoveItems of int
type Event =
| Created of string
| Deactivated
| Renamed of string
| ItemsCheckedIn of int
| ItemsRemoved of int
let apply item = function
| Created _ -> { item with State.isActive = true; }
| Deactivated _ -> { item with State.isActive = false; }
| Renamed _ -> item
| ItemsCheckedIn _ -> item
| ItemsRemoved _ -> item
open Validator
module private Assert =
let validName name = notNull ["The name must not be null."] name <* notEmptyString ["The name must not be empty"] name
let validCount count = validator (fun c -> c > 0) ["The item count must be positive."] count
let inactive state = validator (fun i -> i.isActive = false) ["The item is already deactivated."] state
let exec state =
function
| Create name -> Assert.validName name <?> Created(name)
| Deactivate -> Assert.inactive state <?> Deactivated
| Rename name -> Assert.validName name <?> Renamed(name)
| CheckInItems count -> Assert.validCount count <?> ItemsCheckedIn(count)
| RemoveItems count -> Assert.validCount count <?> ItemsRemoved(count)