Skip to content

Add Result.retract#13721

Merged
dra27 merged 3 commits intoocaml:trunkfrom
dbuenzli:result-retract
Jan 13, 2025
Merged

Add Result.retract#13721
dra27 merged 3 commits intoocaml:trunkfrom
dbuenzli:result-retract

Conversation

@dbuenzli
Copy link
Copy Markdown
Contributor

@dbuenzli dbuenzli commented Jan 8, 2025

Split from #13696 please read the discussion there before commenting on the name.

Retracting the result type for equal success and error type

The Result.retract : ('a, 'a) result -> 'a function is useful when your success and error types eventually end up being the same and it's time to operate on either case uniformly. Formally this is just Result.fold ~ok:Fun.id ~error:Fun.id but I would like to have it as a combinator.

One example of this is when both case end up being an HTTP response and it's time to send it. For now I have it as other names in libraries like for example Http.Response.result and used here. But I'd prefer to have it simply as Result.retract as the pattern can be used in other contexts.

Copy link
Copy Markdown
Contributor

@nojb nojb left a comment

Choose a reason for hiding this comment

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

LGTM

I confess that I do not quite see what the name "retract" refers to, but I don't see any problems with it either.
One could also call it "codiagonal". Anyway, I don't have a strong opinion on naming.

A second approval from a core dev is needed before merging.

Copy link
Copy Markdown
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

LGTM, too!

@dra27 dra27 merged commit 8273fc7 into ocaml:trunk Jan 13, 2025
@dbuenzli dbuenzli deleted the result-retract branch January 13, 2025 21:02
@dbuenzli
Copy link
Copy Markdown
Contributor Author

Thanks!

@dbuenzli dbuenzli mentioned this pull request Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants