diff options
Diffstat (limited to 'src/Xanthous/Util/Inflection.hs')
-rw-r--r-- | src/Xanthous/Util/Inflection.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Xanthous/Util/Inflection.hs b/src/Xanthous/Util/Inflection.hs new file mode 100644 index 000000000000..fc66c0876125 --- /dev/null +++ b/src/Xanthous/Util/Inflection.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE ViewPatterns #-} + +module Xanthous.Util.Inflection + ( toSentence + ) where + +import Xanthous.Prelude + +toSentence :: (MonoFoldable mono, Element mono ~ Text) => mono -> Text +toSentence xs = case reverse . toList $ xs of + [] -> "" + [x] -> x + [b, a] -> a <> " and " <> b + (final : butlast) -> + intercalate ", " (reverse butlast) <> ", and " <> final |