lib: toHex -> toHexString & toBase -> toBaseDigits
This makes the type of these functions more apparent from the name.
This commit is contained in:
parent
e15815e885
commit
6e7822b8f3
|
@ -67,7 +67,7 @@ let
|
||||||
inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor
|
inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor
|
||||||
bitNot boolToString mergeAttrs flip mapNullable inNixShell min max
|
bitNot boolToString mergeAttrs flip mapNullable inNixShell min max
|
||||||
importJSON warn info showWarnings nixpkgsVersion version mod compare
|
importJSON warn info showWarnings nixpkgsVersion version mod compare
|
||||||
splitByAndCompare functionArgs setFunctionArgs isFunction toHex toBase;
|
splitByAndCompare functionArgs setFunctionArgs isFunction toHexString toBaseDigits;
|
||||||
inherit (fixedPoints) fix fix' converge extends composeExtensions
|
inherit (fixedPoints) fix fix' converge extends composeExtensions
|
||||||
makeExtensible makeExtensibleWithCustomName;
|
makeExtensible makeExtensibleWithCustomName;
|
||||||
inherit (attrsets) attrByPath hasAttrByPath setAttrByPath
|
inherit (attrsets) attrByPath hasAttrByPath setAttrByPath
|
||||||
|
|
|
@ -102,13 +102,13 @@ runTests {
|
||||||
expected = 9;
|
expected = 9;
|
||||||
};
|
};
|
||||||
|
|
||||||
testToHex = {
|
testToHexString = {
|
||||||
expr = toHex 250;
|
expr = toHexString 250;
|
||||||
expected = "FA";
|
expected = "FA";
|
||||||
};
|
};
|
||||||
|
|
||||||
testToBase = {
|
testToBaseDigits = {
|
||||||
expr = toBase 2 6;
|
expr = toBaseDigits 2 6;
|
||||||
expected = [ 1 1 0 ];
|
expected = [ 1 1 0 ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -336,13 +336,13 @@ rec {
|
||||||
/* Convert the given positive integer to a string of its hexadecimal
|
/* Convert the given positive integer to a string of its hexadecimal
|
||||||
representation. For example:
|
representation. For example:
|
||||||
|
|
||||||
toHex 0 => "0"
|
toHexString 0 => "0"
|
||||||
|
|
||||||
toHex 16 => "10"
|
toHexString 16 => "10"
|
||||||
|
|
||||||
toHex 250 => "FA"
|
toHexString 250 => "FA"
|
||||||
*/
|
*/
|
||||||
toHex = i:
|
toHexString = i:
|
||||||
let
|
let
|
||||||
toHexDigit = d:
|
toHexDigit = d:
|
||||||
if d < 10
|
if d < 10
|
||||||
|
@ -357,18 +357,18 @@ rec {
|
||||||
"15" = "F";
|
"15" = "F";
|
||||||
}.${toString d};
|
}.${toString d};
|
||||||
in
|
in
|
||||||
lib.concatMapStrings toHexDigit (toBase 16 i);
|
lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
|
||||||
|
|
||||||
/* `toBase base i` converts the positive integer i to a list of its
|
/* `toBaseDigits base i` converts the positive integer i to a list of its
|
||||||
digits in the given base. For example:
|
digits in the given base. For example:
|
||||||
|
|
||||||
toBase 10 123 => [ 1 2 3 ]
|
toBaseDigits 10 123 => [ 1 2 3 ]
|
||||||
|
|
||||||
toBase 2 6 => [ 1 1 0 ]
|
toBaseDigits 2 6 => [ 1 1 0 ]
|
||||||
|
|
||||||
toBase 16 250 => [ 15 10 ]
|
toBaseDigits 16 250 => [ 15 10 ]
|
||||||
*/
|
*/
|
||||||
toBase = base: i:
|
toBaseDigits = base: i:
|
||||||
let
|
let
|
||||||
go = i:
|
go = i:
|
||||||
if i < base
|
if i < base
|
||||||
|
|
|
@ -6,7 +6,7 @@ let
|
||||||
pkgs.lib.optionalString (n < 16) "0" +
|
pkgs.lib.optionalString (n < 16) "0" +
|
||||||
(if n > 255
|
(if n > 255
|
||||||
then throw "Can't have more than 255 nets or nodes!"
|
then throw "Can't have more than 255 nets or nodes!"
|
||||||
else pkgs.lib.toHex n);
|
else pkgs.lib.toHexString n);
|
||||||
in
|
in
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
|
|
Loading…
Reference in New Issue