FSharpPlus
FSharpPlus copied to clipboard
Add more string functions - culture-sensitive functions
Description
https://github.com/fsprojects/FSharpPlus/issues/158#issuecomment-512721780
Regarding the functions taking a culture as parameter, I propose also to discuss them in a different issue, because I think they need more in depth study as I can't find a good proposal at the moment. So let's move them to another issue in order to speed up this one.
"culture-sensitive functions" are functions taking CultureInfo as s parameter.
Candidates
CompareToLower / ToUpperStartsWith / EndsWith- (add more if something is missing)
Ideas
- adding suffix like
WithCulture - using functor(a la OCaml)-like dependency injection
- to be discussed
How would functor logic a la Ocaml like dependency injection look?
String.Cultural(culture).toLower, I guess?
Here's an example:
type CString (c: System.Globalization.CultureInfo) =
member __.ToUpper (s: string) = s.ToUpper (c)
member __.ToLower (s: string) = s.ToLower (c)
Usage:
open System
open FSharpPlus
let String = CString (System.Globalization.CultureInfo.CreateSpecificCulture "PT")
// some code
let r = String.ToLower "Sample String"
// some more code with more calls to localized string functions
So, the let String = CString (System.Globalization.CultureInfo.CreateSpecificCulture "PT") is like opening a module (actually more like aliasing it) with a specific parameter.
Yes, makes sense. Feels like a thing that you should be able to do perhaps nicer in f#, i.e.:
module String = CString.Make (System.Globalization.CultureInfo.CreateSpecificCulture "PT")