-
Notifications
You must be signed in to change notification settings - Fork 110
Operator vs pipe method #154
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
Comments
Would adding new properties to function doSomething(options) {
if (options.pipe) doSomething()
else doSomethingElse()
}
doSomething({ pipe: true })
doSomething({}) // Works now, would break if pipe-property is added to Object.prototype Especially since the method |
Yes, but this would be to Function.prototype. |
I don't think that's what @dfernandez79 is proposing here.
|
ah, true - then yes in that case it’s a nonstarter. |
@noppa You're right, it would break compatibility. Thank you for answering. |
There will be no compatibility problem if we use bind operator: let result = "hello"::pipe(
doubleSay,
capitalize,
exclaim,
); And it seems Emitter proposal use similar pattern: const { on, map, filter, run } = Emitter
run(
on(document, 'click'),
filter(ev => ev.target.tagName === 'BUTTON'),
map(ev => ({ x: ev.clientX, y: ev.clientY })),
coords => console.log(coords),
) Note |
Uh oh!
There was an error while loading. Please reload this page.
I don't know if the GitHub issues are the right place to send comments about the proposal to outsiders. Sorry if my comment is in the wrong place.
Right now I'm working in a DSL like code, and having this infix compose operator will be wonderful. However, while reading the proposal I wonder if adding a
pipe
function (like RxJS, also mentioned in the README) to built-in objects was considered.Advantages:
It works with numbers too if you add parenthesis (today Number has some instance methods too).
Disadvantage:
I'm not proposing a change, but if there are any pointers to related discussions it will be helpful to learn more (I saw discussions about a pipe function but not about a pipe method).
Many thanks
Related Discussions:
There seem to be related discussions:
Some of the comments mention that the global built-in pipe function is not as easy to read as the operator. However, "hard" or "easy" to read sometimes depends on how used you are with the syntax. For example: is hard for me to favor this style
fn(a |> b |> c, x |> y |> z)
over thisfn(a.pipe(b,c),x.pipe(y,z));
.My observations are about compatibility and extensibility; usability will be better answer by studies like the one of #150
The text was updated successfully, but these errors were encountered: