Skip to content

Instantly share code, notes, and snippets.

@lovesegfault
Created April 22, 2021 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovesegfault/e4d2141f1c7846972f2a967b18c234e5 to your computer and use it in GitHub Desktop.
Save lovesegfault/e4d2141f1c7846972f2a967b18c234e5 to your computer and use it in GitHub Desktop.
module Acronym (abbreviate) where
import Data.Char (isSpace, isUpper)
import Data.Text (Text, concat, split, toUpper)
import qualified Data.Text as T
abbreviate :: Text -> Text
abbreviate =
T.concat
. map (\w -> T.pack (take 1 w + (filter isUpper . dropWhile isUpper) w))
. split (\c -> isSpace c || c `elem` ['-', '_'])
-- abbreviate = map toUpper
-- . concatMap (take 1)
-- . split (\c -> isSpace c || c `elem` [ '-', '_' ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment