-
Notifications
You must be signed in to change notification settings - Fork 107
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
Special case unary hack operator? #260
Comments
With the current proposal, it could become this: stream
|> match(%, { topic: 'available' })
|> filter(%, status => ['started', 'exited'].includes(status.type))
|> forEach(%, function*(status) {
yield send(status);
}); |
@nicolo-ribaudo That is one way, but then it wouldn't be a unary function, and would be incompatible with other approaches like |
Could you clarify whether // The original post’s snippet.
stream.
.match({ topic: 'available' }) // Is this a method call?
.filter(status => ['started', 'exited'].includes(status.type))
.forEach(function*(status) {
yield send(status);
}));
}); Assuming that Function.pipe(stream,
match({ topic: 'available' }),
filter(status => ['started', 'exited'].includes(status.type)),
forEach(function*(status) {
yield send(status);
}),
}); Would that satisfy your use case? |
@js-choi Currently, they are instance methods that are bound so that they can be freely disassociated, and they are immutable and so return a new chainable instance with every invocation. That's what they are now, but I'm eyeing refactoring them to be free-standing functions that can be imported individually (which is how I came to be researching the pipe operator in the first place), so the form they ultimately take will depend on what happens here. With my examples such as
At first blush, yes. I'm not seeing why not, and when I read that it makes me feel like perhaps less is truly more. |
There is already a suggested follow-up proposal Tacit unary function application syntax. It does everything the same as your suggestion, but with slightly different syntax. In this case, with the help of stream
|>> match({ topic: 'available' })
|>> filter(status => ['started', 'exited'].includes(status.type))
|>> forEach(function*(status) {
yield send(status);
}); |
I see, although having multiple pipe operators seems questionable to me. For example, I never could be fully comfortable with Clojure threading macros. But either way, it sounds like it's a pretty safe route to go with free standing unary functions since they'll be composable with I'll close this since it sounds like there are several alternatives other than a potential unification by extending the hack syntax to allow for unary functions. |
Just another library author here arriving here out of curiosity about what the future might look like for how to structure our APIs. Effection's use-case is pretty much the same as Rx, so I was excited to try out a potential pipeline operator.
I wanted to re-write one of our actual snippets with it. And If I understand correctly:
would become
Which, like apparently most folks here, I have very mixed feelings about. I like the idea of the raw the power of the Hack pipeline, but having to manually add the placeholder to the end of each combinator in what I envision as my 95% use-case, feels decidedly meh. I find the last case, where you have a multiline operator, to be particularly cumbersome in terms of cognitive load.
That said, it would feel a lot more palatable if there were a special case added for things we know to be unary functions. What if there were a special syntax for unary function expressions; For example
%expr
within a pipeline could be an alias forexpr(%)
.It's still a bit weird, but imho far more readable, and yet still retains the all the powers and advantages of the Hack proposal.
Anyhow, just one datapoint coming into a nearly five years long discussion and missing plenty of context, but I didn't see anything like this in any of the proposals, so figured I throw this out there.
The text was updated successfully, but these errors were encountered: