Capitalize first letter of a string

Aperta
#409 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
haskell

Direzione di ricerca

Inizia esaminando il comportamento esistente di toTitle e le alternative in Scala e Kotlin proposte nell’issue. Confronta la gestione delle stringhe vuote, delle maiuscole e minuscole e dei caratteri Unicode, quindi determina l’API desiderata e documentane il comportamento. Il lavoro è completato quando l’approccio è stato concordato e il comportamento risultante della libreria è coperto da test pertinenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature request question

I am quite surprised by the absence of the common function to capitalize the first letter of a string. Yes, we have toTitle but its behaviour is different to what we have in other languages. Moreover, docs haven't any hints on that topic. Should a library user implement such method himself? If it is not implemented yet then what problems have this approach?

For example, Scala implements the method as following:

  /** Returns this string with first character converted to upper case.
    * If the first character of the string is capitalized, it is returned unchanged.
    * This method does not convert characters outside the Basic Multilingual Plane (BMP).
    */
  def capitalize: String =
    if (s == null || s.length == 0 || !s.charAt(0).isLower) s
    else updated(0, s.charAt(0).toUpper)

Kotlin developers decided that method has non-reliable behaviour in different circumstances, so they deprecated similar method and instead introduced more flexible alternative replaceFirstChar that delegates choosing the type of conversion to user:

public inline fun String.replaceFirstChar(transform: (Char) -> Char): String {
    return if (isNotEmpty()) transform(this[0]) + substring(1) else this
}

// Now instead of capitalize() they suggest to use something like:
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }

We could have something like that in text library. It will help Haskell learners with the knowledge of other languages to adapt to Haskell more quickly.

Lingua principale
Haskell
Stelle
424
Fork
167
Merge medio
1g 21h
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di haskell/text

Tutte le issue di haskell/text

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.