Sha256: 548b38f0090bda5f773600f0efa356e37ed1962c081469bb605db9fa702cd6a7

Contents?: true

Size: 916 Bytes

Versions: 355

Compression:

Stored size: 916 Bytes

Contents

module Acronym
  ( abbreviate
  ) where

import Prelude
import Data.Foldable (foldl)
import Data.String as String
import Data.Char as Char
import Data.List as List
import Data.List (List)
import Data.Char.Unicode as UChar

abbreviate :: String -> String
abbreviate =
  initials <<< List.fromFoldable <<< String.toCharArray

data CharType
  = Upper
  | Lower
  | Space
  | Other


classify :: Char -> CharType
classify '-' = Space
classify ' ' = Space
classify c
  | UChar.isUpper c = Upper
  | UChar.isLower c = Lower
  | otherwise = Other


initials :: List Char -> String
initials =
  let
    next Lower Upper c = String.singleton c
    next Space _ c     = String.singleton (Char.toUpper c)
    next _ _ _ = ""

    step { acc, last } c =
      let charClass = classify c
       in { acc: acc <> next last charClass c
          , last: charClass
          }
  in
    _.acc <<< foldl step { acc: "", last: Space }

Version data entries

355 entries across 355 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.179 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.178 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.177 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.176 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.175 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.174 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.173 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.172 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.171 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.170 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.169 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.167 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.166 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.165 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.164 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.163 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.162 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.161 tracks/purescript/exercises/acronym/examples/src/Acronym.purs
trackler-2.2.1.160 tracks/purescript/exercises/acronym/examples/src/Acronym.purs