-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fn: more fn goodies #8985
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
Merged
guggero
merged 15 commits into
lightningnetwork:master
from
ProofOfKeags:fn/collect-results
Nov 7, 2024
Merged
fn: more fn goodies #8985
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7a7f3bd
fn: fix UnwrapOrFail semantics
ProofOfKeags a741c54
fn: add compound slice functions
ProofOfKeags 5faad77
fn: add conversions between Result and Option
ProofOfKeags 8971c4c
fn: add operations to Result API
ProofOfKeags 5dec354
fn: add transpositions for Option and Result
ProofOfKeags 9bbd327
fn: add Sink to Result
ProofOfKeags a026d64
fn: breaking - fix type variables for better inference
ProofOfKeags c6734ea
fn: breaking - reverse argument order in slice funcs
ProofOfKeags 1805fd6
fn: breaking - polish Either API
ProofOfKeags be50dd9
fn: breaking - remove deprecated Result functions
ProofOfKeags 1480287
fn: breaking - improve naming of option api functions
ProofOfKeags 4d16d5f
fn: breaking - replace AndThen2 with more principled LiftA2Result
ProofOfKeags 5e94704
fn: breaking - give Result's FlatMap proper functor annotation
ProofOfKeags dd7f156
fn: breaking - rename ChainOption to FlatMapOption for consistency
ProofOfKeags 9f35664
fn: breaking - make or else functions accept error argument
ProofOfKeags File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,53 @@ | ||
| package fn | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
| "testing/quick" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestOptionUnwrapOrFail(t *testing.T) { | ||
| require.Equal(t, Some(1).UnwrapOrFail(t), 1) | ||
| } | ||
|
|
||
| func TestSomeToOk(t *testing.T) { | ||
| err := errors.New("err") | ||
| require.Equal(t, Some(1).SomeToOk(err), Ok(1)) | ||
| require.Equal(t, None[uint8]().SomeToOk(err), Err[uint8](err)) | ||
| } | ||
|
|
||
| func TestSomeToOkf(t *testing.T) { | ||
| errStr := "err" | ||
| require.Equal(t, Some(1).SomeToOkf(errStr), Ok(1)) | ||
| require.Equal( | ||
| t, None[uint8]().SomeToOkf(errStr), | ||
| Err[uint8](fmt.Errorf(errStr)), | ||
| ) | ||
| } | ||
|
|
||
| func TestPropTransposeOptResInverts(t *testing.T) { | ||
| f := func(i uint) bool { | ||
| var o Option[Result[uint]] | ||
| switch i % 3 { | ||
| case 0: | ||
| o = Some(Ok(i)) | ||
| case 1: | ||
| o = Some(Errf[uint]("error")) | ||
| case 2: | ||
| o = None[Result[uint]]() | ||
| default: | ||
| return false | ||
| } | ||
|
|
||
| odd := TransposeOptRes(o) == | ||
| TransposeOptRes(TransposeResOpt(TransposeOptRes(o))) | ||
| even := TransposeResOpt(TransposeOptRes(o)) == o | ||
|
|
||
| return odd && even | ||
| } | ||
|
|
||
| require.NoError(t, quick.Check(f, nil)) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.