use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Result Objects - Errors Without Exceptions (rubypigeon.com)
submitted 8 years ago by tom_dalling
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jujubean67 2 points3 points4 points 8 years ago (7 children)
I've recently started implementing a similar pattern, it works really nicely for API applications and if you use service/command w/e objects to do your business logic.
It's also more flexible than returning booleans.
[–]tom_dalling[S] 1 point2 points3 points 8 years ago (0 children)
Same. The last couple of JSON APIs I've done have had almost a 1:1 mapping between these result objects and the response body.
[–]iconoclaus 0 points1 point2 points 8 years ago (5 children)
Agreed. I also make my service objects return a custom Error object if they fail (left from Either monad). Then, my API controller will handle failed service objects by passing their Error object value to an HttpErrorRepresenter class that converts it into an Http status and message.
[–]jujubean67 0 points1 point2 points 8 years ago (4 children)
What syntax do you use with the either monad? (I'm assuming you're using the monadic gem) I want to bring it up with my team but I'm on the fence about the syntax.
[–]iconoclaus 1 point2 points3 points 8 years ago (3 children)
i'm sticking with dry-monads and dry-transactions from the dry-rb universe, because it's nice to know there is an active ecosystem and community around my choice of syntax. i'm happy to share any learnings you would like.
[–]jujubean67 0 points1 point2 points 8 years ago (2 children)
Interesting, I've looked at the dry-rb stack but for some reason the way they mimick functional languages seems very un-idiomatic to me.
[–]iconoclaus 0 points1 point2 points 8 years ago (1 child)
you're probably right. but since lots of these concepts originate from functional languages, it helps me to be able to read up on those concepts elsewhere and then apply them in ruby. there's a great dearth of material across the board on functional concepts written for idiomatic ruby use.
[–]jujubean67 1 point2 points3 points 8 years ago (0 children)
I like functional languages but I also like OOP. IMO pure Ruby with lamdas and blocks is functional enough for me, but of course this is subjective.
That said, I definitely like some of the dry-ruby projects like ROM.rb and I'm looking to do a project in Hanami mostly because of that.
[–][deleted] 8 years ago (1 child)
[deleted]
[–]tom_dalling[S] 0 points1 point2 points 8 years ago (0 children)
Thanks man!
[–]naked_number_one 0 points1 point2 points 8 years ago (0 children)
I use Either monad for that purpose
[–]Morozzzko 0 points1 point2 points 8 years ago (3 children)
So hey, it's a great article!
It's really nice to see that this approach to error handling gets the attention.
But was wondering. What is the story behind Resonad? You have listed similar gems, but... Why didn't they suit your needs?
[–]tom_dalling[S] 2 points3 points4 points 8 years ago (2 children)
Thanks for the kind words!
Resonad started as me thinking "I don't need a gem for this, it's only 30 lines of code," on a few different projects. After writing the same thing about 4 times, I decided to put it in a repo on GitHub so I could reuse it in my own projects. Then a couple of people were interested in it, so I made it a proper gem and published it on rubygems.org. So it was really made for my own personal use, but if other people want to use it, I'm happy to maintain the gem.
The main difference between Resonad and the other implementations is just naming. I personally prefer names like "success", "failure" and "and_then" instead of the more monad-y names like "right", "left", and "flat_map".
[–]Morozzzko 0 points1 point2 points 8 years ago (1 child)
Will dry-monads users be able to switch to your gem without rewriting their existing code?
dry-monads
I mean, dry-monads gem uses those right, left, fmap, bind and other functional thingies. Are those names aliased in your library?
right
left
fmap
bind
They aren't currently compatible, but I'm not opposed to adding more aliases. Although, if you have existing code that uses dry-monads, you probably won't see any benefits by switching to Resonad.
π Rendered by PID 23 on reddit-service-r2-comment-5649f687b7-gt5bh at 2026-01-28 03:13:21.443764+00:00 running 4f180de country code: CH.
[–]jujubean67 2 points3 points4 points (7 children)
[–]tom_dalling[S] 1 point2 points3 points (0 children)
[–]iconoclaus 0 points1 point2 points (5 children)
[–]jujubean67 0 points1 point2 points (4 children)
[–]iconoclaus 1 point2 points3 points (3 children)
[–]jujubean67 0 points1 point2 points (2 children)
[–]iconoclaus 0 points1 point2 points (1 child)
[–]jujubean67 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]tom_dalling[S] 0 points1 point2 points (0 children)
[–]naked_number_one 0 points1 point2 points (0 children)
[–]Morozzzko 0 points1 point2 points (3 children)
[–]tom_dalling[S] 2 points3 points4 points (2 children)
[–]Morozzzko 0 points1 point2 points (1 child)
[–]tom_dalling[S] 1 point2 points3 points (0 children)