-
Notifications
You must be signed in to change notification settings - Fork 110
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
What is this for? #30
Comments
While I personally would really like the idea of a pipeline operator, there is something to be said about language simplicity. Further, a pipeline operator can be achieved by piggy-backing on the :: proposal. usually ::methodName() is passed the argument as this. This can simply be fixed with a simple function.
Now,
Now, while it adds some extra junk to deal with and probably has some run-time cost, it does side-step the many outstanding issues with this proposal. This works today with babel, and side-steps many of the parsing issues around other operators. |
For the case of language simplicity i favor I keep coming back to wanting this in JS. |
@igl I prefer |
The biggest issue i have with @nmn The bind proposal predates the pipe proposal, but as for traction (both proposals starred almost equally on GH) i think the pipe operator could win. Just need some marketing. Could be big if some of the bigger library authors started promoting it. |
Contact your |
FWIW after eagerly adopting IMO the bind operator is a deceptive band aid on the zombie corpse of Javascript OO APIs. While appearing in the abstract to offer a less restrictive and more flexible way of dealing with objects in a way that superficially 'feels' legit to the OOP aesthetic, in practice the Pipe operator is far more flexible, has no pretentions of 'intended usage', and reads better. The lack of implicit abstract semantics makes it less liable to encourage bad derivative code too. |
I implemented piping with a little syntax overhead, here: https://github.com/egeozcan/ppipe Any thoughts? |
@egeozcan your project inspired me to try to do the same. My solution is tiny in comparison, and I like its simplicity: var p = (value) => (fn) => fn ? pipe(fn(value)) : value
/* eslint-disable */
p(2)
(add1)
(square)
(n => n/3)
() // 3
// OR to make it look more like an operator.
p(2
)( add1
)( square
)( n => n - 2
)() // 7 IMO handling promises should be external. So, something like this: const wait = (fn) => (val) => val instanceof Promise ? val.then(fn) : fn(val)
// Now..
p('cats'
)( n => 'funny ' + n
)( fetchGifUrl
)( wait(createImg)
)() // <img src='funny-cat.gif' /> |
Much as I appreciate your efforts, there are existing solutions if one is willing to endure syntactic overhead... |
@nmn cool! actually returning the value when no arguments passed is a @jasmith79 I use ramda very often, but those didn't cover my needs. I'm passionate about mixing normal functions and promise factories. Also, the lack of composability of a single function call and the unary requirement with no way to decide how to pass the results... I agree that mine is a bit hacky but it's more like "this is what I need, and I'd love to have some convenient syntax around this" - definitely not a library to rule them all =) |
const bindP = fn => promise => promise.then(value => fn(value)); Apply it to any function to turn it into one that accepts and returns Promises. Or you could define |
I agree that we probably just want one of |
As I stated in another thread: #23 (comment)
And also: #23 (comment)
Can we carry on this discussion here?
The text was updated successfully, but these errors were encountered: