add amount compare

This commit is contained in:
swrup 2026-03-03 10:45:39 +01:00 committed by Swrup
parent 4bb62e369d
commit 76662bf23c
3 changed files with 11 additions and 10 deletions

View file

@ -47,6 +47,14 @@ let make ~sign ~currency ~value ~fraction =
let currency = String.uppercase_ascii currency in
Ok { sign; currency; value; fraction }
let compare a b =
match String.equal a.currency b.currency with
| false -> Fmt.failwith "amount compare on different currencies"
| true -> (
match Int64.unsigned_compare a.value b.value with
| 0 -> Int32.unsigned_compare a.fraction b.fraction
| n -> n)
module Parser = struct
open Angstrom