query
On this page

pipe

lib.trivial.pipe



Pipes a value through a list of functions, left to right.

Example

pipe 2 [
    (x: x + 2)  # 2 + 2 = 4
    (x: x * 2)  # 4 * 2 = 8
  ]
  => 8
  # ideal to do text transformations
  pipe [ "a/b" "a/c" ] [
    # create the cp command
    (map (file: ''cp "${src}/${file}" $out\n''))
    # concatenate all commands into one string
    lib.concatStrings
    # make that string into a nix derivation
    (pkgs.runCommand "copy-to-out" {})
  ]
  => <drv which copies all files to $out>
The output type of each function has to be the input type
of the next function, and the last function returns the
final value.

Type

pipe :: a -> [<functions>] -> <return type of last function>

Noogle also knows

Aliases