diff --git a/Spintax.cabal b/Spintax.cabal index 4aa8fad..4dbdf71 100644 --- a/Spintax.cabal +++ b/Spintax.cabal @@ -20,6 +20,7 @@ library other-modules: Text.Spintax.RandomPhrase build-depends: attoparsec >= 0.12.1.6 && < 0.15 , base >= 4.7 && < 5 + , either >= 5 && < 6 , extra >= 1.4.3 && < 1.9 , mtl >= 2.2.1 && < 2.4 , mwc-random >= 0.13.3.2 && < 0.16 diff --git a/src/Text/Spintax/RandomPhrase.hs b/src/Text/Spintax/RandomPhrase.hs index e7526fe..88460a4 100644 --- a/src/Text/Spintax/RandomPhrase.hs +++ b/src/Text/Spintax/RandomPhrase.hs @@ -1,9 +1,13 @@ module Text.Spintax.RandomPhrase where -import qualified Data.Text as T +import Data.Either.Combinators (mapRight) +import qualified Data.Text as T import Text.Spintax -type RandomPhrase = T.Text +newtype RandomPhrase = RandomPhrase { unRandomPhrase :: T.Text } + +instance Show RandomPhrase where + show (RandomPhrase t) = show t -- | Generate random passphrase or unique id -- @@ -11,5 +15,7 @@ type RandomPhrase = T.Text -- > Right "coltrane-coconut-kant" -- randomPhrase :: T.Text -> [[T.Text]] -> IO (Either String RandomPhrase) -randomPhrase s ls = spintax $ writeSpintaxExpression s $ writeSpintaxAlternative <$> ls +randomPhrase s ls = do + r <- spintax $ writeSpintaxExpression s $ writeSpintaxAlternative <$> ls + pure (mapRight RandomPhrase r)