elm-community / string-extra

String helper functions for Elm.
http://package.elm-lang.org/packages/elm-community/string-extra/latest
BSD 3-Clause "New" or "Revised" License
34 stars 26 forks source link

Add firstToUpper and firstToLower to change first character's case #58

Open staeter opened 5 months ago

staeter commented 5 months ago

I use this sometimes and it would be nice to have in String.Extra I think

firstToUpper : String -> String
firstToUpper str =
    String.uncons str
        |> Maybe.map (Tuple.mapFirst Char.toUpper)
        |> Maybe.map (\( c, rest ) -> String.fromChar c ++ rest)
        |> Maybe.withDefault str

firstToLower : String -> String
firstToLower str =
    String.uncons str
        |> Maybe.map (Tuple.mapFirst Char.toLower)
        |> Maybe.map (\( c, rest ) -> String.fromChar c ++ rest)
        |> Maybe.withDefault str