-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutable "pipeline assignment" operator #14870
Comments
I also mentioned this here: #14822 Also it shouldn't be too hard to implement. I'd like to see this too ( let var |= ...
# Which is equal to:
let var = $var | ... |
@tmillr Agreed - "shadow assignment" operators would also be nice. I've edited your list with a pointer here for "pipeline assignments", but if you want to enter a separate one for the "shadow assignments", to raise its visibility, that would be great. |
What is the semantics of $foo |= bar | baz And if we follow the assignment expression route is this disallowed? bla | $foo |= bar | baz |
I'd say the same as
I would say disallowed. It should be hmmm I didn't realize that piping directly into an assignment was legal. It's kinda unintuitive because |
$foo |= bar | baz Agree with @tmillr - That would be: $foo = ($foo | bar | baz) And for ... bla | $foo |= bar | baz Today, any value piped into a mutable assignment is ignored unless mut a = 5
1000 | $a += 1
# => 6
1000 | $a += $in
# => 1006 |
Related problem
I'm not sure if I have the naming right, but when dealing with config (or other mutable variables), the convenience of the
+=
and++=
operators only goes so far. When dealing with, for instance, a record that needs amerge
, you still have to resort to$variable = $variable | merge {}
.We currently have:
Describe the solution you'd like
A
PipeAssign
operator, probably|=
which would allow a RHS expression that would simply use the value of the LHS as pipeline input. For example:This comes in handy with longer
$env.config
entries.Describe alternatives you've considered
No response
Additional context and details
No response
The text was updated successfully, but these errors were encountered: