Skip to content

Conversation

@gijswijs
Copy link
Collaborator

@gijswijs gijswijs commented Nov 28, 2025

The FlatMap method for the Result type has been corrected to apply the provided function when the result is Ok and propagate the error unchanged when it is Err.

Comprehensive unit tests have been added to ensure proper functionality of FlatMap, AndThen, and OrElse methods.

Fixes #10401

@gemini-code-assist

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

For a Result[T], FlatMap should apply f when the result is Ok, and
propagate the error unchanged when it's Err. The original code returns r
on Ok and tries to use r.left when Err, which is wrong. This commit
fixes that.

Secondly, the group of FlatMap/AndThen and OrElse functions and methods
are now properly tested with new unit tests.

fixes lightningnetwork#10401
@gijswijs gijswijs changed the title Fix FlatMap implementation in Result type and add OrElse function Fix FlatMap implementation in Result type Nov 28, 2025
@gijswijs gijswijs added this to the v0.20.1 milestone Nov 28, 2025
@gijswijs
Copy link
Collaborator Author

The coveralls checks failing are a false positive.

Coverage before:

go test -cover ./...
ok      github.com/lightningnetwork/lnd/fn/v2   1.030s  coverage: 66.5% of statements

After:

go test -cover ./...
ok      github.com/lightningnetwork/lnd/fn/v2   1.032s  coverage: 68.0% of statements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: FlatMap implementation in fn package is inverted

1 participant