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
Add Result module to Belt #2621
Conversation
It's probably breaking tests because I am not sure of all the places I need to reference Belt_Either, but do you think this looks good? |
I'm just starting to use Belt but this looks to me like it breaks few Belt (or OCaml) conventions:
|
@andreypopp |
@andreypopp |
@chenglou sure, I can make it match the same subset of functions as option |
@chenglou What is the proper way to get the tests running locally?
|
Try |
|
Humm... I suggest you stash the changes, do a cc @bobzhang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping bob or me on discord if you can't make the build work. Sorry for the trouble; we're trying to streamline it still
jscomp/others/belt_Result.ml
Outdated
let mapWithDefault opt default f = mapWithDefaultU opt default (fun[@bs] x -> f x) | ||
|
||
let mapU opt f = match opt with | ||
| Ok x -> Some (f x [@bs]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok (f x [@bs])
jscomp/others/belt_Result.ml
Outdated
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) | ||
|
||
|
||
type ('a, 'b) t = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you like this or should this just point to Js_result.t
?
I've fixed your errors inline. Now the build passes! The interface file is basically like what's from https://github.com/BuckleScript/bucklescript/pull/2622/files. So I think this is good to go. One last question about whether we should alias the type, then that's it. We should redirect folks from Js.Option and Js.Result to here |
@chenglou Thanks for helping me clean it up and showing me how to build it. I switched the type to an alias |
@bobzhang should we change Js.Result to refer to Belt.Result or vice-versa? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This in general looks good to me
jscomp/others/belt_Result.mli
Outdated
|
||
type ('a,'b) t = ('a, 'b) Js_result.t = Ok of 'a | Error of 'b | ||
|
||
val getExn : ('a, 'b) t -> 'a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should getExn
contain some information about Error ?
I think we should flip it and make Js.Result refer to Belt.Result, then put deprecation notices on Js.Result |
@chenglou
|
@mchaver thanks for the PR! =D And sorry for the back-and-forth, but it looks great now. |
Most of these functions are from here
https://gist.github.com/NicolasT/65dad40b203da7c65b4c
I added
rights
,lefts
,arrayLefts
andarrayRights
.