I'm learning F#, and even though I'm able to do whatever I want, parts of my code looks really bad. I would love to get some suggestions on how to improve a couple of functions involving some conditional logic.
let stripLast (punct : char) (word : string) = if word.Length > 0 && word.LastIndexOf(punct) = word.Length - 1 then word.Substring(0, word.Length - 1) else word let countWord (dictionary : Dictionary<string, int>) word = if word = "" || (blacklisted word) then "" |> ignore elif dictionary.ContainsKey(word) then dictionary.[word] <- dictionary.[word] + 1 else dictionary.[word] <- 1
I'm guessing there are ways to make these much more elegant. For instance, the second function uses side-effects on a Dictionary and has return type unit, but I added a branch where I had to use ignore in (probably) a silly way. Please don't change the functionality, but show me a nicer way to write the code.