summary refs log tree commit diff
path: root/lib/debug.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2018-04-02 17:21:35 +0200
committerProfpatsch <mail@profpatsch.de>2018-04-27 18:59:39 +0200
commita5f6cdfd7ef36c0ee3c8bda8b487d1292838862f (patch)
treed760d406be34e555ad39fce953a5822c27e44ad0 /lib/debug.nix
parentf13873f35aaff640e8cf16f3dd9dce01f6661687 (diff)
downloadnixpkgs-a5f6cdfd7ef36c0ee3c8bda8b487d1292838862f.tar
nixpkgs-a5f6cdfd7ef36c0ee3c8bda8b487d1292838862f.tar.gz
nixpkgs-a5f6cdfd7ef36c0ee3c8bda8b487d1292838862f.tar.bz2
nixpkgs-a5f6cdfd7ef36c0ee3c8bda8b487d1292838862f.tar.lz
nixpkgs-a5f6cdfd7ef36c0ee3c8bda8b487d1292838862f.tar.xz
nixpkgs-a5f6cdfd7ef36c0ee3c8bda8b487d1292838862f.tar.zst
nixpkgs-a5f6cdfd7ef36c0ee3c8bda8b487d1292838862f.zip
lib/debug: add traceValFn, traceValSeqFn, traceValSeqNFn
Being able to modify the value on-the-fly before printing is very useful in
practice.
Diffstat (limited to 'lib/debug.nix')
-rw-r--r--lib/debug.nix9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/debug.nix b/lib/debug.nix
index d163e60b695..d5e9473ff77 100644
--- a/lib/debug.nix
+++ b/lib/debug.nix
@@ -17,7 +17,8 @@ rec {
 
   traceIf = p: msg: x: if p then trace msg x else x;
 
-  traceVal = x: trace x x;
+  traceValFn = f: x: trace (f x) x;
+  traceVal = traceValFn id;
   traceXMLVal = x: trace (builtins.toXML x) x;
   traceXMLValMarked = str: x: trace (str + builtins.toXML x) x;
 
@@ -44,9 +45,11 @@ rec {
                (modify depth snip x)) y;
 
   /* `traceSeq`, but the same value is traced and returned */
-  traceValSeq = v: traceVal (builtins.deepSeq v v);
+  traceValSeqFn = f: v: traceVal f (builtins.deepSeq v v);
+  traceValSeq = traceValSeqFn id;
   /* `traceValSeq` but with fixed depth */
-  traceValSeqN = depth: v: traceSeqN depth v v;
+  traceValSeqNFn = f: depth: v: traceSeqN depth (f v) v;
+  traceValSeqN = traceValSeqNFn id;
 
 
   # this can help debug your code as well - designed to not produce thousands of lines