Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is probably related to #25233 and #34340 but simpler I guess. and I think this is quite consistent with Julia's own naming convention. But I'm not sure if this would cause ambiguity. Currently
|>
will return a function due to the method!(f::Function) = (xs...)->!f(xs...)
, but I feel this is quite duplicated with<
anyways.TL;DR
Currently, we only have one pipe operator, and the
|>
is overloaded in Base to be a sugar for function calls. However, in the case that a callable object has side effects, the developers will not be able to force their users to name the variable name with a postfix!
, thus the side effect will not be explicit. One option is to not define the callable method for the object, but instead, define!>
operator if the pipe is used more often in the APIExample
Originally assume we have an object defined as following
since there could be a few different kinds of this object
MyObject1
,MyObject2
, and they may take different properties, we can easily have a chain of these calls but with side effect. So it's natural to defineand let users write
where
x1
,x2
,x3
are instances ofMyObject
or other subtypes ofAbstractMyObject
. However, this API drops the!
on the pipe operator, so if we have!>
, we can just defineand users will have to write
which is way more explicit.
Use cases
This idea is motivated by the blocks defined in Yao. Each block in Yao defines a quantum gate/circuit that acts on a quantum register. However, by the non-cloning theorem, one is not allowed to
copy
the register by physics law, thus all the operations on the register will and have to be in place. And it is very natural to let users use pipe operator to define a long quantum circuit, e.gr |> H |> H |> H |> X |> Y
etc. I think it'd be nice if we could use!>
instead of|>
. The implicit side effect API is currently a few of our users complain about making it easier to write bugs, but we cannot easily drop this pipe API since it plays a key role in our API and really simplifies a lot things.I think @GiggleLiu also has some use cases in reversible programming, not sure if @tkf has any comments, I came across from your reply on discourse. and in case if anyone is interested on discourse post: https://discourse.julialang.org/t/parse-pip-operator-for-side-effect-calls/38857/6