Capitalizing a string in Elm

I seem to semi-regularly need a function to capitalize a string in Elm, and this isn’t included in either the core String library or NoRedInk’s String.Extra. So here is a super simple implementation:

import String exposing (left, dropLeft, toUpper)

capitalize : String -> String
capitalize str =
  (left 1 >> toUpper) str ++ dropLeft 1 str

Leave a Reply

Your email address will not be published. Required fields are marked *