FSharpPlus icon indicating copy to clipboard operation
FSharpPlus copied to clipboard

Add more string functions - culture-sensitive functions

Open cannorin opened this issue 6 years ago • 4 comments

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

  • Compare
  • ToLower / ToUpper
  • StartsWith / EndsWith
  • (add more if something is missing)

Ideas

  • adding suffix like WithCulture
  • using functor(a la OCaml)-like dependency injection
  • to be discussed

cannorin avatar Jul 29 '19 10:07 cannorin

How would functor logic a la Ocaml like dependency injection look?

wallymathieu avatar Jul 30 '19 17:07 wallymathieu

String.Cultural(culture).toLower, I guess?

cannorin avatar Jul 31 '19 04:07 cannorin

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.

gusty avatar Jul 31 '19 08:07 gusty

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")

wallymathieu avatar Aug 01 '19 14:08 wallymathieu