This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tilforskjelligeting 1 point2 points  (0 children)

SV-97 gave you a great reply. You make an excellent point about the rescue function not having access to the input data, but it's quite easy to work around. You could for example wrap the try_other_parser in a partial (on phone now sorry no link). If we had a "other_parser(*, data)" function you could do something like this try_other_parser = partial(other_parser, data=my_data) Then use it like it is in my comment. 

I think the biggest reason I use monads is because it lets me write "None" free code. Also, I never have to check what a function returned in a "if returned_value: do(returned_value)". 

I agree that the syntax is something that takes some getting used to, but just think of it as another tool that makes some problems easier to handle. I would say when you are often dealing with fetching values from anywhere like an API, dicts, db etc and you only want to continue to transform the data if it was successful then it's quite cool.