Concat in FSharp.Core.String vs Concat in System.String
I noticed that Microsoft.FSharp.Core
there are lowercase String.concat
and uppercase in there System.String.Concat
with a few overloads. Intellisense picks one or the other if I type String.c
orSystem.String.C
Are functions String.xyz
in Microsoft.FSharp.Core
preference to functions, System.String.Xyz
or vice versa? What are the advantages and disadvantages of each type of feature?
In general, what are the advantages and disadvantages of using functions in FSharp.Core?
source to share
I'm not sure if these 2 are equivalent:
FSharp is String.concat
used to concatenate a sequence of lines into one line using a delimeter:
let strings = [ "tomatoes"; "bananas"; "apples" ]
let fullString = String.concat ", " strings
printfn "%s" fullString
System.String.Concat
used to concatenate two (or more) separate lines together.
System.String.Join
is the same as FSharp String.concat
- it's just a wrapper for it:
[<CompiledName("Concat")>]
let concat sep (strings : seq<string>) =
String.Join(sep, strings)
As you write F #, you'll find it more idiomatic to call F # functions over those from other .NET collections. For example, you can partially apply F # functions; you cannot use .NET method calls.
eg. a function that always matches a space can be defined like this:
let concatWithSpace xs =
String.concat " " xs
It becomes more useful if you model it as part of your domain eg. instead concatWithSpace
it could be called formatReportElements
or something with a meaning.
source to share