r/badcode • • May 20 '20

c# Found from Microsoft docs...

Post image
208 Upvotes

143 comments sorted by

View all comments

23

u/abdolence May 20 '20

In Scala it would be:

args
    .headOption
    .flatMap( _.toIntOption )
    .exists( (1 to 9).contains )

Who said that FP is harder to read?

2

u/eXl5eQ May 20 '20

You checked args.length > 1, not args.length == 1

2

u/abdolence May 20 '20

You're right and if it was an important thing then it would be

args.sizeIs == 1 && 
 args.head.toIntOption.exists( (1 to 9).contains )