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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1284c50
Add Belt.Either
mchaver 2d54f83
Fix notes
mchaver 3f52573
Update function names
mchaver 130db55
Move to result
mchaver e0d98bf
Rename things
mchaver db3f192
Update Makefile
mchaver 9b55b6e
Match functions from Belt_Option
mchaver f86537c
Update belt_Result.ml
chenglou 94937b6
Update belt_Result.ml
chenglou b3e40ee
Update Makefile
chenglou 2a77fbf
Update .depend
chenglou df16b63
Use Js_result.t
mchaver 139e81e
Add constructors
mchaver fae05c5
Deprecate Js.Result
mchaver 00c5302
add belt_result.js
mchaver 3f48d05
Merged master
mchaver 0033bf6
revert js_result, use deprecation only
mchaver File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
(* Copyright (C) 2017 Authors of BuckleScript | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* In addition to the permissions granted to you by the LGPL, you may combine | ||
* or link a "work that uses the Library" with a publicly distributed version | ||
* of this file to produce a combined library or application, then distribute | ||
* that combined work under the terms of your choosing, with no requirement | ||
* to comply with the obligations normally placed on you by section 4 of the | ||
* LGPL version 3 (or the corresponding section of a later version of the LGPL | ||
* should you choose to use a later version). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) | ||
|
||
|
||
type ('a,'b) t = ('a, 'b) Js_result.t = Ok of 'a | Error of 'b | ||
|
||
let getExn = function | ||
| Js_result.Ok x -> x | ||
| Js_result.Error _ -> [%assert "getExn"] | ||
|
||
let mapWithDefaultU opt default f = match opt with | ||
| Js_result.Ok x -> (f x [@bs]) | ||
| Js_result.Error _ -> default | ||
|
||
let mapWithDefault opt default f = mapWithDefaultU opt default (fun[@bs] x -> f x) | ||
|
||
let mapU opt f = match opt with | ||
| Js_result.Ok x -> Js_result.Ok (f x [@bs]) | ||
| Js_result.Error y -> Js_result.Error y | ||
|
||
let map opt f = mapU opt (fun[@bs] x -> f x) | ||
|
||
let flatMapU opt f = match opt with | ||
| Js_result.Ok x -> (f x [@bs]) | ||
| Js_result.Error y -> Js_result.Error y | ||
|
||
let flatMap opt f = flatMapU opt (fun[@bs] x -> f x) | ||
|
||
let getWithDefault opt default = match opt with | ||
| Js_result.Ok x -> x | ||
| Js_result.Error _ -> default | ||
|
||
let isOk = function | ||
| Js_result.Ok _ -> true | ||
| Js_result.Error _ -> false | ||
|
||
let isError = function | ||
| Js_result.Ok _ -> false | ||
| Js_result.Error _ -> true | ||
|
||
let eqU a b f = match (a, b) with | ||
| (Ok a, Ok b) -> f a b [@bs] | ||
| (Error _, Ok _) | ||
| (Ok _, Error _) -> false | ||
| (Error _, Error _) -> true | ||
|
||
let eq a b f = eqU a b (fun[@bs] x y -> f x y) | ||
|
||
let cmpU a b f = match (a, b) with | ||
| (Ok a, Ok b) -> f a b [@bs] | ||
| (Error _, Ok _) -> -1 | ||
| (Ok _, Error _) -> 1 | ||
| (Error _, Error _) -> 0 | ||
|
||
let cmp a b f = cmpU a b (fun[@bs] x y -> f x y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(* Copyright (C) 2017 Authors of BuckleScript | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* In addition to the permissions granted to you by the LGPL, you may combine | ||
* or link a "work that uses the Library" with a publicly distributed version | ||
* of this file to produce a combined library or application, then distribute | ||
* that combined work under the terms of your choosing, with no requirement | ||
* to comply with the obligations normally placed on you by section 4 of the | ||
* LGPL version 3 (or the corresponding section of a later version of the LGPL | ||
* should you choose to use a later version). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) | ||
|
||
(** {!Belt.Result} | ||
|
||
Utilities for result data type. | ||
*) | ||
|
||
type ('a,'b) t = ('a, 'b) Js_result.t = Ok of 'a | Error of 'b | ||
|
||
val getExn : ('a, 'b) t -> 'a | ||
val mapWithDefaultU : ('a, 'c) t -> 'b -> ('a -> 'b [@bs]) -> 'b | ||
val mapWithDefault : ('a, 'c) t -> 'b -> ('a -> 'b) -> 'b | ||
val mapU : ('a, 'c) t -> ('a -> 'b [@bs]) -> ('b, 'c) t | ||
val map : ('a, 'c) t -> ('a -> 'b) -> ('b, 'c) t | ||
val flatMapU : ('a, 'c) t -> ('a -> ('b, 'c) t [@bs]) -> ('b, 'c) t | ||
val flatMap : ('a, 'c) t -> ('a -> ('b, 'c) t) -> ('b, 'c) t | ||
val getWithDefault : ('a, 'b) t -> 'a -> 'a | ||
val isOk : ('a, 'b) t -> bool | ||
val isError : ('a, 'b) t -> bool | ||
val eqU : ('a, 'c) t -> ('b, 'd) t -> ('a -> 'b -> bool [@bs]) -> bool | ||
val eq : ('a, 'c) t -> ('b, 'd) t -> ('a -> 'b -> bool) -> bool | ||
val cmpU : ('a, 'c) t -> ('b, 'd) t -> ('a -> 'b -> int [@bs]) -> int | ||
val cmp : ('a, 'c) t -> ('b, 'd) t -> ('a -> 'b -> int) -> int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aboutError ?