I am new to functional programming and F #, and there is a lot of information on how to do this (removing certain characters from a string) in F #, but I came across the following function and would like to help a bit to understand exactly what is happening:
let stripchars chars str =
Seq.fold
(fun (str: string) chr ->
str.Replace(chr |> Char.ToUpper |> string, "").Replace(chr |> Char.ToLower |> string, ""))
str chars
I used the stripchars function by calling it in the split function, which I defined as follows:
let split (str : string) =
((stripchars "?,.,!,," str).Split ' ') |> Array.toList
What is hard for me to understand now, in the stripchars function, when the "chars" argument is passed containing a sequence of characters to remove from the str string, it is not even used in the code until the last string "str chars". So how can this work?
source
share