Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
staeter opened this issue May 28, 2024 · 0 comments
Open

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

staeter opened this issue May 28, 2024 · 0 comments

Comments

@staeter
Copy link

staeter commented May 28, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant