Hacker News new | ask | show | jobs
by stefanchrobot 2175 days ago
...or pattern matching in case of dynamically-typed languages:

  case some_operation() do
    {:ok, result} -> # do something with result
    {:error, error} -> # handle the error
  end
1 comments

You lose the ability to make sure you've handled an error AOT, but sure, this feature is pretty much the same as a sum type except that it's structural. When I used to write typescript, there were plenty of times I was happy to have it's union types!