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.

@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

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some code style minor nits - otherwise LGTM

Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - I think we should address the comments and then merge.

@lightninglabs-deploy
Copy link

@gijswijs, remember to re-request review from reviewers when ready

@saubyk saubyk added this to lnd v0.20 Jan 6, 2026
@saubyk saubyk moved this to In review in lnd v0.20 Jan 6, 2026
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
@yyforyongyu yyforyongyu merged commit d3ce622 into lightningnetwork:master Jan 6, 2026
39 of 41 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in lnd v0.20 Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[bug]: FlatMap implementation in fn package is inverted

4 participants