mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Merge pull request #11131 from rhendric/rhendric/pipe-operators
libexpr: experimental pipe operators
This commit is contained in:
commit
6ec123ad6b
10 changed files with 174 additions and 9 deletions
28
doc/manual/rl-next/pipe-operators.md
Normal file
28
doc/manual/rl-next/pipe-operators.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
synopsis: "Add `pipe-operators` experimental feature"
|
||||
prs:
|
||||
- 11131
|
||||
---
|
||||
|
||||
This is a draft implementation of [RFC 0148](https://github.com/NixOS/rfcs/pull/148).
|
||||
|
||||
The `pipe-operators` experimental feature adds [`<|` and `|>` operators][pipe operators] to the Nix language.
|
||||
*a* `|>` *b* is equivalent to the function application *b* *a*, and
|
||||
*a* `<|` *b* is equivalent to the function application *a* *b*.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
nix-repl> 1 |> builtins.add 2 |> builtins.mul 3
|
||||
9
|
||||
|
||||
nix-repl> builtins.add 1 <| builtins.mul 2 <| 3
|
||||
7
|
||||
```
|
||||
|
||||
`<|` and `|>` are right and left associative, respectively, and have lower precedence than any other operator.
|
||||
These properties may change in future releases.
|
||||
|
||||
See [the RFC](https://github.com/NixOS/rfcs/pull/148) for more examples and rationale.
|
||||
|
||||
[pipe operators]: @docroot@/language/operators.md#pipe-operators
|
|
@ -26,13 +26,17 @@
|
|||
| Logical conjunction (`AND`) | *bool* `&&` *bool* | left | 12 |
|
||||
| Logical disjunction (`OR`) | *bool* <code>\|\|</code> *bool* | left | 13 |
|
||||
| [Logical implication] | *bool* `->` *bool* | right | 14 |
|
||||
| [Pipe operator] (experimental) | *expr* `\|>` *func* | left | 15 |
|
||||
| [Pipe operator] (experimental) | *func* `<\|` *expr* | right | 15 |
|
||||
|
||||
[string]: ./types.md#type-string
|
||||
[path]: ./types.md#type-path
|
||||
[number]: ./types.md#type-float <!-- TODO(@rhendric, #10970): rationalize this -->
|
||||
[number]: ./types.md#type-float
|
||||
[list]: ./types.md#list
|
||||
[attribute set]: ./types.md#attribute-set
|
||||
|
||||
<!-- TODO(@rhendric, #10970): ^ rationalize number -> int/float -->
|
||||
|
||||
## Attribute selection
|
||||
|
||||
> **Syntax**
|
||||
|
@ -176,3 +180,34 @@ Equivalent to `!`*b1* `||` *b2*.
|
|||
|
||||
[Logical implication]: #logical-implication
|
||||
|
||||
## Pipe operators
|
||||
|
||||
- *a* `|>` *b* is equivalent to *b* *a*
|
||||
- *a* `<|` *b* is equivalent to *a* *b*
|
||||
|
||||
> **Example**
|
||||
>
|
||||
> ```
|
||||
> nix-repl> 1 |> builtins.add 2 |> builtins.mul 3
|
||||
> 9
|
||||
>
|
||||
> nix-repl> builtins.add 1 <| builtins.mul 2 <| 3
|
||||
> 7
|
||||
> ```
|
||||
|
||||
> **Warning**
|
||||
>
|
||||
> This syntax is part of an
|
||||
> [experimental feature](@docroot@/contributing/experimental-features.md)
|
||||
> and may change in future releases.
|
||||
>
|
||||
> To use this syntax, make sure the
|
||||
> [`pipe-operators` experimental feature](@docroot@/contributing/experimental-features.md#xp-feature-pipe-operators)
|
||||
> is enabled.
|
||||
> For example, include the following in [`nix.conf`](@docroot@/command-ref/conf-file.md):
|
||||
>
|
||||
> ```
|
||||
> extra-experimental-features = pipe-operators
|
||||
> ```
|
||||
|
||||
[Pipe operator]: #pipe-operators
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue