Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pipe last implementation #53

Closed
lessp opened this issue Feb 20, 2020 · 2 comments
Closed

Pipe last implementation #53

lessp opened this issue Feb 20, 2020 · 2 comments

Comments

@lessp
Copy link

lessp commented Feb 20, 2020

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?

@aantron
Copy link
Owner

aantron commented Feb 20, 2020

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:

open Promise.PipeFirst;

On JS, the module is empty, because we want to forward to BuckleScript's operator:

promise/src/js/promise.rei

Lines 230 to 231 in 6b9ff51

module PipeFirst: {
};

On native, the module defines the operator for unary functions (it's the desugared syntax, but -> maps to it):

module PipeFirst: {
let (|.): ('a, 'a => 'b) => 'b;
};

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 (#52).

@lessp
Copy link
Author

lessp commented Feb 22, 2020

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. 🙂

@lessp lessp closed this as completed Feb 26, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants