Created
December 15, 2024 13:11
-
-
Save adept/951990134b72c148e8aeb597fc9b7b57 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Asset_v1 = struct | |
type t = {serial:string option; inventory_id:string option; other_data:string} | |
let set_inventory_id asset inv_id = {asset with inventory_id = Some inv_id} | |
let needs_inventory_id asset = | |
match asset.inventory_id with | |
| None -> true | |
| Some _ -> false | |
end | |
module Asset_v2 = struct | |
type id = | |
| Serial of string | |
| Inventory_id of string | |
| Serial_and_inventory_id of {serial:string; inventory_id: string} | |
type t = { id : id; other_data : string } | |
let set_inventory_id asset inv_id = | |
let new_id = | |
match asset.id with | |
| Inventory_id _ -> Inventory_id inv_id | |
| Serial serial -> Serial_and_inventory_id {serial; inventory_id=inv_id} | |
| Serial_and_inventory_id info -> Serial_and_inventory_id {info with inventory_id = inv_id} | |
in | |
{asset with id = new_id} | |
let needs_inventory_id asset = | |
match asset.id with | |
| Inventory_id _ | Serial_and_inventory_id _ -> false | |
| Serial _ -> true | |
end | |
module Asset_v3 = struct | |
type id = | |
| Serial of string | |
| Inventory_id of string | |
| Serial_and_inventory_id of {serial:string; inventory_id: string} | |
| RFID of string | |
type t = { id : id; other_data : string } | |
let set_inventory_id asset inv_id = | |
let new_id = | |
match asset.id with | |
| Inventory_id _ -> Inventory_id inv_id | |
| Serial serial -> Serial_and_inventory_id {serial; inventory_id=inv_id} | |
| Serial_and_inventory_id info -> Serial_and_inventory_id {info with inventory_id = inv_id} | |
| RFID _ -> Inventory_id inv_id | |
in | |
{asset with id = new_id} | |
let needs_inventory_id asset = | |
match asset.id with | |
| Inventory_id _ | Serial_and_inventory_id _ -> false | |
| Serial _ | RFID _ -> true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment