bahaghari/lib: simplify fromDec implementation

This commit is contained in:
Gabriel Arazas 2024-02-29 16:13:49 +08:00
parent e5083302b2
commit 9fde40828b
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC

View File

@ -129,17 +129,9 @@ rec {
# open a can of worms about implementing this with stringy types.
fromDec = decimal:
let
iter = product: value:
let
quotient = value / base;
remainder = value - (base * quotient);
baseDigit = glyphSet.${builtins.toString remainder} + product;
digits = pkgs.lib.toBaseDigits base decimal;
in
if quotient <= 0
then baseDigit
else iter baseDigit quotient;
in
iter "" decimal;
pkgs.lib.concatMapStrings (d: glyphSet.${builtins.toString d}) digits;
toDec = digit:
let