fix: trim start

This commit is contained in:
orion 2023-12-16 13:27:07 -06:00
parent c479776340
commit 01f844b2d2
Signed by: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -243,12 +243,15 @@ pad n pq@(Proquint segs) =
else
pq
trim :: Proquint -> Proquint
trim (Proquint segs) = Proquint $ Array.dropWhile (_ == segmentZero) segs
toString :: Proquint -> String
toString (Proquint segments) = intercalate "-" $ map segmentToString segments
fromString :: String -> Either String Proquint
fromString "" = Right $ Proquint []
fromString s = map Proquint $ traverse segmentFromString $ String.split (wrap "-") s
fromString s = map (trim <<< Proquint) $ traverse segmentFromString $ String.split (wrap "-") s
fromInt :: Int -> Proquint
fromInt n = fromBits $ unsafePerformEffect do
@ -292,4 +295,4 @@ fromBits buf =
| x >= len = segs
| otherwise = go (segs <> [ segmentFromBits $ octets x ]) (x + 2)
in
Proquint $ go [] 0
trim $ Proquint $ go [] 0