Skip to content

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

Description

@staeter

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions