From d68092c6c3caf35beb7cddc51a3f0e962fd8f58b Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 5 Jun 2024 18:48:52 +0200 Subject: lib.mapNixDir': init --- lib/pure.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pure.nix b/lib/pure.nix index 5d4b96b..edf7292 100644 --- a/lib/pure.nix +++ b/lib/pure.nix @@ -82,11 +82,18 @@ let stripAttr = converge (filterAttrsRecursive (n: v: v != {} && v != null)); - mapNixDir = f: x: { + # mapNixDir :: (path -> a) -> listOf path -> listOf a + # mapNixDir :: (path -> a) -> path -> a + mapNixDir = f: mapNixDir' (const f); + + # mapNixDir' :: (str -> path -> a) -> listOf path -> listOf a + # mapNixDir' :: (str -> path -> a) -> path -> a + mapNixDir' = f: x: { list = foldl' mergeAttrs {} (map (mapNixDir1 f) x); path = mapNixDir1 f x; }.${typeOf x}; + # mapNixDir1 :: (str -> path -> a) -> path -> a mapNixDir1 = f: dirPath: let toPackageName = name: @@ -97,8 +104,9 @@ let (relPath: let name = removeSuffix ".nix" relPath; path = dirPath + "/${relPath}"; + pname = toPackageName name; in - nameValuePair (toPackageName name) (f path)) + nameValuePair pname (f pname path)) (attrNames (filterAttrs isNixDirEntry (readDir dirPath)))); -- cgit v1.2.3