treewide: fold -> foldr

This commit is contained in:
Ben Siraphob 2021-01-25 13:57:48 +07:00
parent aa8868c7cc
commit 1c2a2b0a08
18 changed files with 26 additions and 26 deletions

View File

@ -5,7 +5,7 @@ let
inherit (builtins) head tail length; inherit (builtins) head tail length;
inherit (lib.trivial) and; inherit (lib.trivial) and;
inherit (lib.strings) concatStringsSep sanitizeDerivationName; inherit (lib.strings) concatStringsSep sanitizeDerivationName;
inherit (lib.lists) fold concatMap concatLists; inherit (lib.lists) fold foldr concatMap concatLists;
in in
rec { rec {
@ -152,8 +152,8 @@ rec {
=> { a = [ 2 3 ]; } => { a = [ 2 3 ]; }
*/ */
foldAttrs = op: nul: list_of_attrs: foldAttrs = op: nul: list_of_attrs:
fold (n: a: foldr (n: a:
fold (name: o: foldr (name: o:
o // { ${name} = op n.${name} (a.${name} or nul); } o // { ${name} = op n.${name} (a.${name} or nul); }
) a (attrNames n) ) a (attrNames n)
) {} list_of_attrs; ) {} list_of_attrs;
@ -433,7 +433,7 @@ rec {
=> true => true
*/ */
matchAttrs = pattern: attrs: assert isAttrs pattern; matchAttrs = pattern: attrs: assert isAttrs pattern;
fold and true (attrValues (zipAttrsWithNames (attrNames pattern) (n: values: foldr and true (attrValues (zipAttrsWithNames (attrNames pattern) (n: values:
let pat = head values; val = head (tail values); in let pat = head values; val = head (tail values); in
if length values == 1 then false if length values == 1 then false
else if isAttrs pat then isAttrs val && matchAttrs pat val else if isAttrs pat then isAttrs val && matchAttrs pat val

View File

@ -77,11 +77,11 @@ rec {
# Output : are reqs satisfied? It's asserted. # Output : are reqs satisfied? It's asserted.
checkReqs = attrSet: argList: condList: checkReqs = attrSet: argList: condList:
( (
fold lib.and true foldr lib.and true
(map (x: let name = (head x); in (map (x: let name = (head x); in
((checkFlag attrSet name) -> ((checkFlag attrSet name) ->
(fold lib.and true (foldr lib.and true
(map (y: let val=(getValue attrSet argList y); in (map (y: let val=(getValue attrSet argList y); in
(val!=null) && (val!=false)) (val!=null) && (val!=false))
(tail x))))) condList)); (tail x))))) condList));
@ -177,7 +177,7 @@ rec {
# merge attributes with custom function handling the case that the attribute # merge attributes with custom function handling the case that the attribute
# exists in both sets # exists in both sets
mergeAttrsWithFunc = f: set1: set2: mergeAttrsWithFunc = f: set1: set2:
fold (n: set: if set ? ${n} foldr (n: set: if set ? ${n}
then setAttr set n (f set.${n} set2.${n}) then setAttr set n (f set.${n} set2.${n})
else set ) else set )
(set2 // set1) (attrNames set2); (set2 // set1) (attrNames set2);
@ -196,7 +196,7 @@ rec {
mergeAttrsNoOverride = { mergeLists ? ["buildInputs" "propagatedBuildInputs"], mergeAttrsNoOverride = { mergeLists ? ["buildInputs" "propagatedBuildInputs"],
overrideSnd ? [ "buildPhase" ] overrideSnd ? [ "buildPhase" ]
}: attrs1: attrs2: }: attrs1: attrs2:
fold (n: set: foldr (n: set:
setAttr set n ( if set ? ${n} setAttr set n ( if set ? ${n}
then # merge then # merge
if elem n mergeLists # attribute contains list, merge them by concatenating if elem n mergeLists # attribute contains list, merge them by concatenating
@ -224,7 +224,7 @@ rec {
mergeAttrBy2 = { mergeAttrBy = lib.mergeAttrs; } mergeAttrBy2 = { mergeAttrBy = lib.mergeAttrs; }
// (maybeAttr "mergeAttrBy" {} x) // (maybeAttr "mergeAttrBy" {} x)
// (maybeAttr "mergeAttrBy" {} y); in // (maybeAttr "mergeAttrBy" {} y); in
fold lib.mergeAttrs {} [ foldr lib.mergeAttrs {} [
x y x y
(mapAttrs ( a: v: # merge special names using given functions (mapAttrs ( a: v: # merge special names using given functions
if x ? ${a} if x ? ${a}

View File

@ -305,7 +305,7 @@ rec {
warn = msg: builtins.trace "warning: ${msg}"; warn = msg: builtins.trace "warning: ${msg}";
info = msg: builtins.trace "INFO: ${msg}"; info = msg: builtins.trace "INFO: ${msg}";
showWarnings = warnings: res: lib.fold (w: x: warn w x) res warnings; showWarnings = warnings: res: lib.foldr (w: x: warn w x) res warnings;
## Function annotations ## Function annotations

View File

@ -12,7 +12,7 @@ let
# E.g. if some `options` came from modules in ${pkgs.customModules}/nix, # E.g. if some `options` came from modules in ${pkgs.customModules}/nix,
# you'd need to include `extraSources = [ pkgs.customModules ]` # you'd need to include `extraSources = [ pkgs.customModules ]`
prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources); prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip; stripAnyPrefixes = lib.flip (lib.foldr lib.removePrefix) prefixesToStrip;
optionsDoc = buildPackages.nixosOptionsDoc { optionsDoc = buildPackages.nixosOptionsDoc {
inherit options revision; inherit options revision;

View File

@ -386,7 +386,7 @@ let
}; };
}; };
idsAreUnique = set: idAttr: !(fold (name: args@{ dup, acc }: idsAreUnique = set: idAttr: !(foldr (name: args@{ dup, acc }:
let let
id = builtins.toString (builtins.getAttr idAttr (builtins.getAttr name set)); id = builtins.toString (builtins.getAttr idAttr (builtins.getAttr name set));
exists = builtins.hasAttr id acc; exists = builtins.hasAttr id acc;

View File

@ -39,7 +39,7 @@ let
if c x then true if c x then true
else lib.traceSeqN 1 x false; else lib.traceSeqN 1 x false;
in traceXIfNot isConfig; in traceXIfNot isConfig;
merge = args: fold (def: mergeConfig def.value) {}; merge = args: foldr (def: mergeConfig def.value) {};
}; };
overlayType = mkOptionType { overlayType = mkOptionType {

View File

@ -279,7 +279,7 @@ let
src_plan = plan; src_plan = plan;
tsformat = timestampFormat; tsformat = timestampFormat;
zend_delay = toString sendDelay; zend_delay = toString sendDelay;
} // fold (a: b: a // b) {} ( } // foldr (a: b: a // b) {} (
map mkDestAttrs (builtins.attrValues destinations) map mkDestAttrs (builtins.attrValues destinations)
); );

View File

@ -193,7 +193,7 @@ let
# We need to handle the last column specially here, because it's # We need to handle the last column specially here, because it's
# open-ended (command + args). # open-ended (command + args).
lines = [ labels labelDefaults ] ++ (map (l: init l ++ [""]) masterCf); lines = [ labels labelDefaults ] ++ (map (l: init l ++ [""]) masterCf);
in fold foldLine (genList (const 0) (length labels)) lines; in foldr foldLine (genList (const 0) (length labels)) lines;
# Pad a string with spaces from the right (opposite of fixedWidthString). # Pad a string with spaces from the right (opposite of fixedWidthString).
pad = width: str: let pad = width: str: let
@ -202,7 +202,7 @@ let
in str + optionalString (padWidth > 0) padding; in str + optionalString (padWidth > 0) padding;
# It's + 2 here, because that's the amount of spacing between columns. # It's + 2 here, because that's the amount of spacing between columns.
fullWidth = fold (width: acc: acc + width + 2) 0 maxWidths; fullWidth = foldr (width: acc: acc + width + 2) 0 maxWidths;
formatLine = line: concatStringsSep " " (zipListsWith pad maxWidths line); formatLine = line: concatStringsSep " " (zipListsWith pad maxWidths line);

View File

@ -79,7 +79,7 @@ in
systemd.services = systemd.services =
lib.fold ( s : acc : acc // lib.foldr ( s : acc : acc //
{ {
"autossh-${s.name}" = "autossh-${s.name}" =
let let

View File

@ -160,7 +160,7 @@ in
users.groups.nylon.gid = config.ids.gids.nylon; users.groups.nylon.gid = config.ids.gids.nylon;
systemd.services = fold (a: b: a // b) {} nylonUnits; systemd.services = foldr (a: b: a // b) {} nylonUnits;
}; };
} }

View File

@ -87,7 +87,7 @@ with lib;
}; };
config = mkIf (cfg != []) { config = mkIf (cfg != []) {
systemd.services = fold (a: b: a // b) {} ( systemd.services = foldr (a: b: a // b) {} (
mapAttrsToList (name: qtcfg: { mapAttrsToList (name: qtcfg: {
"quicktun-${name}" = { "quicktun-${name}" = {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];

View File

@ -351,7 +351,7 @@ in
config = mkIf (cfg.networks != { }) { config = mkIf (cfg.networks != { }) {
environment.etc = fold (a: b: a // b) { } environment.etc = foldr (a: b: a // b) { }
(flip mapAttrsToList cfg.networks (network: data: (flip mapAttrsToList cfg.networks (network: data:
flip mapAttrs' data.hosts (host: text: nameValuePair flip mapAttrs' data.hosts (host: text: nameValuePair
("tinc/${network}/hosts/${host}") ("tinc/${network}/hosts/${host}")

View File

@ -19,7 +19,7 @@ let
${ethtool} -s ${interface} ${methodParameter {inherit method password;}} ${ethtool} -s ${interface} ${methodParameter {inherit method password;}}
''; '';
concatStrings = fold (x: y: x + y) ""; concatStrings = foldr (x: y: x + y) "";
lines = concatStrings (map (l: line l) interfaces); lines = concatStrings (map (l: line l) interfaces);
in in

View File

@ -126,7 +126,7 @@ let
else showWarnings config.warnings baseSystem; else showWarnings config.warnings baseSystem;
# Replace runtime dependencies # Replace runtime dependencies
system = fold ({ oldDependency, newDependency }: drv: system = foldr ({ oldDependency, newDependency }: drv:
pkgs.replaceDependency { inherit oldDependency newDependency drv; } pkgs.replaceDependency { inherit oldDependency newDependency drv; }
) baseSystemAssertWarn config.system.replaceRuntimeDependencies; ) baseSystemAssertWarn config.system.replaceRuntimeDependencies;

View File

@ -75,7 +75,7 @@ let
else "${convertedFont}"); else "${convertedFont}");
}); });
bootDeviceCounters = fold (device: attr: attr // { ${device} = (attr.${device} or 0) + 1; }) {} bootDeviceCounters = foldr (device: attr: attr // { ${device} = (attr.${device} or 0) + 1; }) {}
(concatMap (args: args.devices) cfg.mirroredBoots); (concatMap (args: args.devices) cfg.mirroredBoots);
convertedFont = (pkgs.runCommand "grub-font-converted.pf2" {} convertedFont = (pkgs.runCommand "grub-font-converted.pf2" {}

View File

@ -8,7 +8,7 @@ let
keyedEncDevs = filter (dev: dev.encrypted.keyFile != null) encDevs; keyedEncDevs = filter (dev: dev.encrypted.keyFile != null) encDevs;
keylessEncDevs = filter (dev: dev.encrypted.keyFile == null) encDevs; keylessEncDevs = filter (dev: dev.encrypted.keyFile == null) encDevs;
anyEncrypted = anyEncrypted =
fold (j: v: v || j.encrypted.enable) false encDevs; foldr (j: v: v || j.encrypted.enable) false encDevs;
encryptedFSOptions = { encryptedFSOptions = {

View File

@ -68,7 +68,7 @@ assert stdenv.isLinux;
let let
# Combine the `features' attribute sets of all the kernel patches. # Combine the `features' attribute sets of all the kernel patches.
kernelFeatures = lib.fold (x: y: (x.features or {}) // y) ({ kernelFeatures = lib.foldr (x: y: (x.features or {}) // y) ({
iwlwifi = true; iwlwifi = true;
efiBootStub = true; efiBootStub = true;
needsCifsUtils = true; needsCifsUtils = true;

View File

@ -77,7 +77,7 @@ rec {
in if fn != null then [{key = fn;}] ++ xs in if fn != null then [{key = fn;}] ++ xs
else xs; else xs;
in pkgs.lib.fold foundDeps [] deps; in pkgs.lib.foldr foundDeps [] deps;
}; };