treewide: fold -> foldr

Changed files
+26 -26
lib
nixos
doc
manual
modules
config
misc
services
system
activation
boot
loader
grub
tasks
pkgs
os-specific
linux
kernel
tools
typesetting
tex
+4 -4
lib/attrsets.nix
···
inherit (builtins) head tail length;
inherit (lib.trivial) and;
inherit (lib.strings) concatStringsSep sanitizeDerivationName;
-
inherit (lib.lists) fold concatMap concatLists;
+
inherit (lib.lists) fold foldr concatMap concatLists;
in
rec {
···
=> { a = [ 2 3 ]; }
*/
foldAttrs = op: nul: list_of_attrs:
-
fold (n: a:
-
fold (name: o:
+
foldr (n: a:
+
foldr (name: o:
o // { ${name} = op n.${name} (a.${name} or nul); }
) a (attrNames n)
) {} list_of_attrs;
···
=> true
*/
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
if length values == 1 then false
else if isAttrs pat then isAttrs val && matchAttrs pat val
+5 -5
lib/deprecated.nix
···
# Output : are reqs satisfied? It's asserted.
checkReqs = attrSet: argList: condList:
(
-
fold lib.and true
+
foldr lib.and true
(map (x: let name = (head x); in
((checkFlag attrSet name) ->
-
(fold lib.and true
+
(foldr lib.and true
(map (y: let val=(getValue attrSet argList y); in
(val!=null) && (val!=false))
(tail x))))) condList));
···
# merge attributes with custom function handling the case that the attribute
# exists in both sets
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})
else set )
(set2 // set1) (attrNames set2);
···
mergeAttrsNoOverride = { mergeLists ? ["buildInputs" "propagatedBuildInputs"],
overrideSnd ? [ "buildPhase" ]
}: attrs1: attrs2:
-
fold (n: set:
+
foldr (n: set:
setAttr set n ( if set ? ${n}
then # merge
if elem n mergeLists # attribute contains list, merge them by concatenating
···
mergeAttrBy2 = { mergeAttrBy = lib.mergeAttrs; }
// (maybeAttr "mergeAttrBy" {} x)
// (maybeAttr "mergeAttrBy" {} y); in
-
fold lib.mergeAttrs {} [
+
foldr lib.mergeAttrs {} [
x y
(mapAttrs ( a: v: # merge special names using given functions
if x ? ${a}
+1 -1
lib/trivial.nix
···
warn = msg: builtins.trace "warning: ${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
+1 -1
nixos/doc/manual/default.nix
···
# E.g. if some `options` came from modules in ${pkgs.customModules}/nix,
# you'd need to include `extraSources = [ pkgs.customModules ]`
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 {
inherit options revision;
+1 -1
nixos/modules/config/users-groups.nix
···
};
};
-
idsAreUnique = set: idAttr: !(fold (name: args@{ dup, acc }:
+
idsAreUnique = set: idAttr: !(foldr (name: args@{ dup, acc }:
let
id = builtins.toString (builtins.getAttr idAttr (builtins.getAttr name set));
exists = builtins.hasAttr id acc;
+1 -1
nixos/modules/misc/nixpkgs.nix
···
if c x then true
else lib.traceSeqN 1 x false;
in traceXIfNot isConfig;
-
merge = args: fold (def: mergeConfig def.value) {};
+
merge = args: foldr (def: mergeConfig def.value) {};
};
overlayType = mkOptionType {
+1 -1
nixos/modules/services/backup/znapzend.nix
···
src_plan = plan;
tsformat = timestampFormat;
zend_delay = toString sendDelay;
-
} // fold (a: b: a // b) {} (
+
} // foldr (a: b: a // b) {} (
map mkDestAttrs (builtins.attrValues destinations)
);
+2 -2
nixos/modules/services/mail/postfix.nix
···
# We need to handle the last column specially here, because it's
# open-ended (command + args).
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 = width: str: let
···
in str + optionalString (padWidth > 0) padding;
# 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);
+1 -1
nixos/modules/services/networking/autossh.nix
···
systemd.services =
-
lib.fold ( s : acc : acc //
+
lib.foldr ( s : acc : acc //
{
"autossh-${s.name}" =
let
+1 -1
nixos/modules/services/networking/nylon.nix
···
users.groups.nylon.gid = config.ids.gids.nylon;
-
systemd.services = fold (a: b: a // b) {} nylonUnits;
+
systemd.services = foldr (a: b: a // b) {} nylonUnits;
};
}
+1 -1
nixos/modules/services/networking/quicktun.nix
···
};
config = mkIf (cfg != []) {
-
systemd.services = fold (a: b: a // b) {} (
+
systemd.services = foldr (a: b: a // b) {} (
mapAttrsToList (name: qtcfg: {
"quicktun-${name}" = {
wantedBy = [ "multi-user.target" ];
+1 -1
nixos/modules/services/networking/tinc.nix
···
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 mapAttrs' data.hosts (host: text: nameValuePair
("tinc/${network}/hosts/${host}")
+1 -1
nixos/modules/services/networking/wakeonlan.nix
···
${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);
in
+1 -1
nixos/modules/system/activation/top-level.nix
···
else showWarnings config.warnings baseSystem;
# Replace runtime dependencies
-
system = fold ({ oldDependency, newDependency }: drv:
+
system = foldr ({ oldDependency, newDependency }: drv:
pkgs.replaceDependency { inherit oldDependency newDependency drv; }
) baseSystemAssertWarn config.system.replaceRuntimeDependencies;
+1 -1
nixos/modules/system/boot/loader/grub/grub.nix
···
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);
convertedFont = (pkgs.runCommand "grub-font-converted.pf2" {}
+1 -1
nixos/modules/tasks/encrypted-devices.nix
···
keyedEncDevs = filter (dev: dev.encrypted.keyFile != null) encDevs;
keylessEncDevs = filter (dev: dev.encrypted.keyFile == null) encDevs;
anyEncrypted =
-
fold (j: v: v || j.encrypted.enable) false encDevs;
+
foldr (j: v: v || j.encrypted.enable) false encDevs;
encryptedFSOptions = {
+1 -1
pkgs/os-specific/linux/kernel/generic.nix
···
let
# 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;
efiBootStub = true;
needsCifsUtils = true;
+1 -1
pkgs/tools/typesetting/tex/nix/default.nix
···
in if fn != null then [{key = fn;}] ++ xs
else xs;
-
in pkgs.lib.fold foundDeps [] deps;
+
in pkgs.lib.foldr foundDeps [] deps;
};