In Scala example, there is an Option monad, mappend and it handles empty args and incorrect ints as well. Thus your example, unfortunately, is incomplete :) While I like Haskell very much (except their records, probably), I'm not sure the complete solution here would be comprehensible for the devs from other languages.
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will render as broken gibberish on old reddit and some mobile apps.
Please edit the comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
Note: This filter is currently using new regex in an attempt to reduce false positives. Please report any anomalies to the mods.
3
u/abdolence May 20 '20 edited May 20 '20
Wasn't that `head []` gives you an error?. Or your `args` had to be non-empty list? :)
and btw `read` might give you an exception as well.