lib/debug: add traceValFn, traceValSeqFn, traceValSeqNFn

Being able to modify the value on-the-fly before printing is very useful in
practice.
This commit is contained in:
Profpatsch 2018-04-02 17:21:35 +02:00
parent f13873f35a
commit a5f6cdfd7e
2 changed files with 11 additions and 7 deletions

View file

@ -17,7 +17,8 @@ rec {
traceIf = p: msg: x: if p then trace msg x else x; 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; traceXMLVal = x: trace (builtins.toXML x) x;
traceXMLValMarked = str: x: trace (str + builtins.toXML x) x; traceXMLValMarked = str: x: trace (str + builtins.toXML x) x;
@ -44,9 +45,11 @@ rec {
(modify depth snip x)) y; (modify depth snip x)) y;
/* `traceSeq`, but the same value is traced and returned */ /* `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 */ /* `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 # this can help debug your code as well - designed to not produce thousands of lines

View file

@ -115,11 +115,12 @@ let
unknownModule mkOption; unknownModule mkOption;
inherit (types) isType setType defaultTypeMerge defaultFunctor inherit (types) isType setType defaultTypeMerge defaultFunctor
isOptionType mkOptionType; isOptionType mkOptionType;
inherit (debug) addErrorContextToAttrs traceIf traceVal inherit (debug) addErrorContextToAttrs traceIf traceVal traceValFn
traceXMLVal traceXMLValMarked traceSeq traceSeqN traceValSeq traceXMLVal traceXMLValMarked traceSeq traceSeqN traceValSeq
traceValSeqN traceShowVal traceShowValMarked traceValSeqFn traceValSeqN traceValSeqNFn traceShowVal
showVal traceCall traceCall2 traceCall3 traceValIfNot runTests traceShowValMarked showVal traceCall traceCall2 traceCall3
testAllTrue strict traceCallXml attrNamesToStr; traceValIfNot runTests testAllTrue strict traceCallXml
attrNamesToStr;
inherit (misc) maybeEnv defaultMergeArg defaultMerge foldArgs inherit (misc) maybeEnv defaultMergeArg defaultMerge foldArgs
defaultOverridableDelayableArgs composedArgsAndFun defaultOverridableDelayableArgs composedArgsAndFun
maybeAttrNullable maybeAttr ifEnable checkFlag getValue maybeAttrNullable maybeAttr ifEnable checkFlag getValue