Closed lessp closed 4 years ago
It's feasible to do, but I'd be concerned about increasing bundle size on the JS side, for a feature that isn't a "primary" concern for JS-only work. For now, I added a PipeFirst
module (you may have already seen it). To write code that works on both native and JS with it, you can do:
On JS, the module is empty, because we want to forward to BuckleScript's operator:
On native, the module defines the operator for unary functions (it's the desugared syntax, but ->
maps to it):
This is good enough for most uses, which are partially-applied binary functions from Promise
.
Obviously, using ->
a lot on mostly-native code is going to stick out. I don't know yet what to do about that :/ I figured this library's main contribution is to JS, rather than to native, so it's best to follow BuckleScript conventions.
Note that the pipe operators might become less important over time, as people switch more and more conclusively to OCaml 4.08+ on the native side, and BuckleScript releases a Reason with let*
support. Then, let*
syntax might replace many uses of the pipe operator with promise functions (https://github.com/aantron/promise/issues/52).
Thanks for always providing such elaborate and thoughtful answers!
I had entirely forgotten about let-operators pretty much solving this completely! Personally, I can see how it makes sense to wait, that considered. 🙂
Previously Promise was pipe-last. Within the BuckleScript the main API's are pipe-first (a separate discussion 😄). For me, who's also interested in the native side, where pipe-last undoubtedly is the norm, what would be your view on providing both options?