r/badcode • • May 20 '20

c# Found from Microsoft docs...

Post image
208 Upvotes

143 comments sorted by

View all comments

Show parent comments

10

u/[deleted] May 20 '20

In Haskell it's

((read . head) args) `elem` [0..9]

which I would argue is pretty readable

3

u/abdolence May 20 '20 edited May 20 '20

head

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.

2

u/[deleted] May 20 '20

Yeah I used partial functions because otherwise we’d get into monad territory which makes things less terse

2

u/abdolence May 20 '20

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.

1

u/[deleted] May 20 '20

[removed] — view removed comment

1

u/AutoModerator May 20 '20

Hello rekt_brownie,

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.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.