Nix: Add an infix reverse-application operator

Created on 28 Apr 2018  路  7Comments  路  Source: NixOS/nix

I couldn't find this handy pipe-like operator:

val (|>) : 'a -> ('a -> 'b) -> 'b
Reverse-application operator: x |> f |> g is exactly equivalent to g (f (x)).

Example use case:
builtins.readDir "/dir" |> builtins.attrNames
instead of
buitins.attrNames (builtins.readDir "/dir")

feature

All 7 comments

The extensive haskell subcommunity in Nix will probably want $ too, if this goes in 馃槃

@copumpkin you mean https://github.com/NixOS/nix/issues/1845 ? :smile:

And before you know it, Nix will support Agda-style arbitrary mixfix operators 馃槃

nix-repl> let __div = x: y: y x; in
          builtins.readDir "/etc" / builtins.attrNames / builtins.length
77
nix-repl> let __mul = x: y: if builtins.typeOf y != "lambda" then x y else z: x (y z); in 
          builtins.length * builtins.attrNames * builtins.readDir "/etc"
77

ans so on (https://github.com/NixOS/nix/issues/861)

Yes please!

Any progress?

No, there are no plans to add this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eqyiel picture eqyiel  路  3Comments

bflyblue picture bflyblue  路  3Comments

chexxor picture chexxor  路  4Comments

bryanhuntesl picture bryanhuntesl  路  3Comments

ericsagnes picture ericsagnes  路  4Comments