Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do `fun` lambda expressions have shorthand syntax?

Tags:

lambda

f#

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

like image 936
rasx Avatar asked Jun 04 '26 19:06

rasx


1 Answers

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)
like image 97
Brian Berns Avatar answered Jun 07 '26 16:06

Brian Berns



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!