-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "and" and "or" functions and macros (#47)
- Loading branch information
Showing
8 changed files
with
179 additions
and
1 deletion.
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,24 @@ | ||
Try.@and(expressions...) | ||
|
||
Evaluate to the first "failure" result of one of the `expressions` and do not evaluate | ||
the rest of the `expressions`. Otherwise, evaluate all `expressions` and return the last | ||
result. | ||
|
||
# Extended help | ||
|
||
## Examples | ||
|
||
```julia | ||
julia> using Try | ||
|
||
julia> Try.@and(Ok(1), Ok(2), Ok(3)) | ||
Try.Ok: 3 | ||
|
||
julia> Try.@and(Ok(1), Err(2), (println("this is not evaluated"); Ok(3))) | ||
Try.Err: 2 | ||
|
||
julia> Try.@and(Some(1), Some(2), Some(3)) | ||
Some(3) | ||
|
||
julia> Try.@and(Some(1), nothing, (println("this is not evaluated"); Some(3))) | ||
``` |
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,24 @@ | ||
Try.@or(expressions...) | ||
|
||
Evaluate to the first "successful" result of one of the `expressions` and do not evaluate | ||
the rest of the `expressions`. Otherwise, evaluate all `expressions` and return the last | ||
result. | ||
|
||
# Extended help | ||
|
||
## Examples | ||
|
||
```julia | ||
julia> using Try | ||
|
||
julia> Try.@or(Err(1), Ok(2), (println("this is not evaluated"); Err(3))) | ||
Try.Ok: 2 | ||
|
||
julia> Try.@or(Err(1), Err(2), Err(3)) | ||
Try.Err: 3 | ||
|
||
julia> Try.@or(nothing, Some(2), (println("this is not evaluated"); Some(3))) | ||
Some(2) | ||
|
||
julia> Try.@or(nothing, nothing, nothing) | ||
``` |
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,22 @@ | ||
Try.and(results...) | ||
|
||
Return the first "failure" or the last result if all results are "success." | ||
|
||
# Extended help | ||
|
||
## Examples | ||
|
||
```julia | ||
julia> using Try | ||
|
||
julia> Try.and(Ok(1), Ok(2), Ok(3)) | ||
Try.Ok: 3 | ||
|
||
julia> Try.and(Ok(1), Err(2), Ok(3)) | ||
Try.Err: 2 | ||
|
||
julia> Try.and(Some(1), Some(2), Some(3)) | ||
Some(3) | ||
|
||
julia> Try.and(Some(1), nothing, Some(3)) | ||
``` |
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,22 @@ | ||
Try.or(results...) | ||
|
||
Return the first "successful" result or the last result if all results are "failures." | ||
|
||
# Extended help | ||
|
||
## Examples | ||
|
||
```julia | ||
julia> using Try | ||
|
||
julia> Try.or(Err(1), Ok(2), Err(3)) | ||
Try.Ok: 2 | ||
|
||
julia> Try.or(Err(1), Err(2), Err(3)) | ||
Try.Err: 3 | ||
|
||
julia> Try.or(nothing, Some(2), Some(3)) | ||
Some(2) | ||
|
||
julia> Try.or(nothing, nothing, nothing) | ||
``` |
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