i want to make sure that i am not missing out on readable-but-terse F# syntax: is my use of fun below too verbose?
let toCamelCase word indexes =
let mapping i c =
match (indexes |> List.contains i) with
| true -> Char.ToUpper(c)
| _ when Char.IsUpper(c) -> Char.ToLower(c)
| _ -> c
word |> String.mapi mapping
[
("fsharP", [0; 1])
("nAtiveinterop", [0; 6])
("taskbuildereXtensions", [0; 4; 11])
("microsoftword", [0; 9])
]
|> List.map (fun (word, indexes) -> (word, indexes) ||> toCamelCase)
also, do let me know whether there can be improvements elsewhere in the code above
In some functional languages, an uncurry function is pretty common:
let uncurry f (a,b) = f a b
Then you can write |> List.map (uncurry toCamelCase) instead.
Alternatively, you can just simplify what you have now a little to:
|> List.map (fun pair -> pair ||> toCamelCase)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With