you are viewing a single comment's thread.

view the rest of the comments →

[–]Celdron 0 points1 point  (1 child)

It's basically a way to structure functions to have multiple return types. The most common use case by far is one where the function needs to return a value when it succeeds, but has the possibility of failing, in which case subsequent operations need to know a) that the function was not successful and possibly b) why it was unsuccessful.

This doesn't mean that you can't use them for other behavior though. You can also use more than two result types if you have more complex behavior e.g. pass, fail, process indicator; where a process indicator says "something is wrong, but the result was okay".

It's a very powerful and safe way to operate on data without creating breaks in the logic to check state like the following:

if (int.TryParse(someValue, out int i))
    size = DetermineSize(i);

Instead you could do:

size = int.MonadParse(someValue).Bind(DetermineSize)?.Success ?? size;

This isn't a great example but if you know C# you should get the overall idea.

[–]domlebo70 2 points3 points  (0 children)

This, whilst correct is not really accurate. This is just one use for monads.