From 9fde40828b2f339927729862f42ced5627117aea Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 29 Feb 2024 16:13:49 +0800 Subject: [PATCH] bahaghari/lib: simplify `fromDec` implementation --- subprojects/bahaghari/lib/trivial.nix | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/subprojects/bahaghari/lib/trivial.nix b/subprojects/bahaghari/lib/trivial.nix index eaca42d8..9baba075 100644 --- a/subprojects/bahaghari/lib/trivial.nix +++ b/subprojects/bahaghari/lib/trivial.nix @@ -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; - in - if quotient <= 0 - then baseDigit - else iter baseDigit quotient; + digits = pkgs.lib.toBaseDigits base decimal; in - iter "" decimal; + pkgs.lib.concatMapStrings (d: glyphSet.${builtins.toString d}) digits; toDec = digit: let