-- |
-- Module      :  Text.Inflections.Underscore
-- Copyright   :  © 2016 Justin Leitgeb
-- License     :  MIT
--
-- Maintainer  :  Justin Leitgeb <justin@stackbuilders.com>
-- Stability   :  experimental
-- Portability :  portable
--
-- Conversion to phrases separated by underscores.

{-# LANGUAGE OverloadedStrings #-}

module Text.Inflections.Underscore
  ( underscore )
where

import Data.Text (Text)
import Text.Inflections.Types
import qualified Data.Text as T

-- | Separate given words by underscores.
--
-- >>> foo  <- SomeWord <$> mkWord "foo"
-- >>> bar  <- SomeWord <$> mkAcronym "bar"
-- >>> bazz <- SomeWord <$> mkWord "bazz"
-- >>> underscore [foo,bar,bazz]
-- "foo_bar_bazz"
underscore
  :: [SomeWord] -- ^ Input words to separate with underscores
  -> Text       -- ^ The underscored String
underscore :: [SomeWord] -> Text
underscore = Text -> [Text] -> Text
T.intercalate Text
"_" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text -> Text) -> SomeWord -> Text
unSomeWord Text -> Text
T.toLower)