diff options
author | Profpatsch <mail@profpatsch.de> | 2019-10-18 17:57:33 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2019-10-21 13:19:16 +0200 |
commit | 8252861507ef85b45f739c63f27d4e9a80b31b31 (patch) | |
tree | fc6346d3bf0ed219cab72332d17ffb2fe857dac1 /lib/default.nix | |
parent | 360e57a567a7cb8fbe3d1f41dbb09238eccddefa (diff) |
lib/trivial: add `pipe` function
`pipe` is a useful operator for creating pipelines of functions. It works around the usual problem of e.g. string operations becoming deeply nested functions. In principle, there are four different ways this function could be written: pipe val [ f1 .. fn ] pipe val [ fn .. f1 ] compose [ f1 .. fn ] val compose [ fn .. f1 ] val The third and fourth form mirror composition of functions, they would be the same as e.g. `(f1 << f2 << f3 .. << fn) val`. However, it is not clear which direction the list should have (as one can see in the second form, which is the most absurd. In order not to confuse users, we decide for the most “intuitive” form, which mirrors the way unix pipes work (thus the name `pipe`). The flow of data goes from left to right. Co-Authored-By: Silvan Mosberger <infinisil@icloud.com>
Diffstat (limited to 'lib/default.nix')
-rw-r--r-- | lib/default.nix | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/default.nix b/lib/default.nix index f293a1defb11c..74d508ec1d6e3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -57,8 +57,8 @@ let hasAttr head isAttrs isBool isInt isList isString length lessThan listToAttrs pathExists readFile replaceStrings seq stringLength sub substring tail; - inherit (trivial) id const concat or and bitAnd bitOr bitXor bitNot - boolToString mergeAttrs flip mapNullable inNixShell min max + inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor + bitNot boolToString mergeAttrs flip mapNullable inNixShell min max importJSON warn info showWarnings nixpkgsVersion version mod compare splitByAndCompare functionArgs setFunctionArgs isFunction; inherit (fixedPoints) fix fix' converge extends composeExtensions |