about summary refs log tree commit diff
path: root/src/Xanthous/Util/Inflection.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xanthous/Util/Inflection.hs')
-rw-r--r--src/Xanthous/Util/Inflection.hs15
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