Replies: 2 comments
-
There's nothing built-in, no. This question has come up before, so you might want to look through the Issues to see examples of how you could do this with the |
Beta Was this translation helpful? Give feedback.
-
@louthy OK, thanks, that gives me plenty of ways to waste the entire afternoon reading up and playing! I also came across this post, which mentions a book on category theory for programmers. Always wanted to understand that, so I bought it. Something else to occupy why otherwise free time (as if!). Thanks again. I'll probably be back with more questions, but let's see how I get on with it first. |
Beta Was this translation helpful? Give feedback.
-
Either
is useful (amongst other things) for when some code might fail, so you return either the left type if it fails, or the right type f it succeeds (or is it the other way round?).I'm interested in expanding the idea to include a third generic type in case the operation didn't fail, but wasn't completed for other reasons. For example, if my code stores the date that an entity was last updated, then when a modified entity is sent to the context for saving, I could check if the data in the database had been modified since the date stamp on the incoming entity. If so, I would want a way of passing back the message that the incoming data was out of date. This isn't an error in the same way as (say) a foreign key constraint violation, so I wouldn't want to use the left type, but it's not a success, as the incoming data wasn't saved.
I know I could look in the source code for
Either
and copy it, adding the third type, but I was wondering if the package already has anything that would help me.Anyone any comments? Thanks
Beta Was this translation helpful? Give feedback.
All reactions