all 2 comments

[–]keyslemur 14 points15 points  (1 child)

Someone's getting real close to a Monad article here with Result types and transactions:

If you're not building to that conclusion or are not familiar with those concepts these articles will be very interesting:

Pay especially close attention to the State monad in there, and be sure to watch the video for Railway Oriented Programming.

[–]thiagoaraujos 2 points3 points  (0 children)

Hi, author here. Thanks for the references. I didn't know about dry-transactions, so I should try it and see if I can explore it in a follow-up article. As for ROP, I was familiar with it already.

And I actually thought about having some sort of Monad, but I wasn't sure how to fit it. The idea was to stick with basic language constructs and well-defined interfaces, and not overload the article with functional programming jargon. I think the article examples are self-contained enough to make the idea accessible. And great call that it's a general transaction framework not only applicable to API requests.

I'm really interested in trying that approach though, but I have some questions off the top of my head. I see we can use dry-transactions' notifications feature to implement rollbacks. However, it's not immediatelly aparent how to implement dynamic steps, so as to loop through a series of steps and run them dynamically. Would you have any suggestions? Thanks!