Last active
December 8, 2015 10:42
-
-
Save jovaneyck/dc66da9fb2d52ccdbc9f to your computer and use it in GitHub Desktop.
How to write this in idiomatic F#?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let isValid input = | |
input | |
|> parse | |
/*smelly and doesn't scale, what's the F# way of combining predicates?*/ | |
|> (fun p -> predicate1 p && predicate2 p) |
Ahh, I love the smell of idiomatic F# in the morning!
Thanks for the pointers!
I've watched your ROP talk before but thought it'd be a tad too much to just solve the adventofcode problems. Just give me a few more weeks with F# and I'll get there :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can easily write helper functions:
so your code becomes:
If you are doing input validation though, I suggest you try avoid booleans if you can, and think about transformation oriented approaches. That is, taking an input and transforming it to either a success (with associated data), or a a failure (with associated error messages). I have a talk about this approach that might be useful: http://fsharpforfunandprofit.com/rop/
Cheers!