Skip to content

Call #to_result on step inputs#38

Merged
timriley merged 8 commits intomainfrom
convert-to-result
Feb 28, 2026
Merged

Call #to_result on step inputs#38
timriley merged 8 commits intomainfrom
convert-to-result

Conversation

@timriley
Copy link
Member

@timriley timriley commented Feb 11, 2026

This allows other objects to be used that convert to results, like Try, Maybe, etc. from Dry Monads.

I'll be working on making those available to operation classes via an extension in another PR.

This allows other objects to be used that convert to results, like Try, Failure, etc. from Dry Monads.
@timriley
Copy link
Member Author

OK, this PR is ready to go again, I think.

I've also added new documentation alongside it: a "Other monads" page with high-level examples of how you can use other monads from Dry Monads and where they are helpful. This is now possible thanks to our .to_result call!

@timriley
Copy link
Member Author

cc'ing @dry-rb/maintainers for review of the docs

@timriley timriley requested a review from a team February 13, 2026 06:33
Copy link
Member

@aaronmallen aaronmallen left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

Copy link
Member

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

I love it. Thanks a lot for this simple but powerful addition to the gem!!

There's a typo in the index.html.md file that I think would prevent the link to the new docs from being found.

- configuration
- extensions
- design-pattern
- other-moands
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- other-moands
- other-monads

super <<~MSG
Your step must return `Success(..)` or `Failure(..)`, \
from `Dry::Monads::Result`. Instead, it was `#{result.inspect}`.
Your step must return `Success(..)` or `Failure(..)`, or an object with `.to_result`. Instead, it was `#{result.inspect}`.
Copy link
Member

Choose a reason for hiding this comment

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

Actually a #to_result is not enough because of the #value_or requirement. I'd like to get rid of #to_value and have pattern matching implemented as a requirement instead, allowing other to bring their #to_result types, but that's not possible because of this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've covered this in the docs, but as I explained above, I felt it was better to keep this exception message simpler.

@timriley
Copy link
Member Author

Thanks for all the feedback everybody! This is looking ready to go. Will merge this in now. I don't plan to release this until at least a week from now, so if you have any further feedback, please feel free to share it :)

@timriley timriley merged commit 32d85f9 into main Feb 28, 2026
7 checks passed
@timriley timriley deleted the convert-to-result branch February 28, 2026 01:59
@wuarmin
Copy link
Contributor

wuarmin commented Mar 2, 2026

Great! Thank you

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.

5 participants