Is there a better way to handle :ok tuples?

Sometime ago I also had that impression, " why I need to match a tuple when I just want to return the value" the problem is that what really happens when you do res = f() it’s actually doing a pattern matching, not the usual assignment, in that case you are accepting anything, an value or error, requiring you to do the pattern matching, which is more work. Now if you want the result or the process can blew up, some functions have a bang ! version which will raise if failed, like file = File.read!("foo.txt"), you can look up to that too

1 Like