about summary refs log tree commit diff
path: root/users/aspen/xanthous/src/Xanthous/Util/Inflection.hs
diff options
context:
space:
mode:
Diffstat (limited to 'users/aspen/xanthous/src/Xanthous/Util/Inflection.hs')
-rw-r--r--users/aspen/xanthous/src/Xanthous/Util/Inflection.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/users/aspen/xanthous/src/Xanthous/Util/Inflection.hs b/users/aspen/xanthous/src/Xanthous/Util/Inflection.hs
new file mode 100644
index 0000000000..724f2339dd
--- /dev/null
+++ b/users/aspen/xanthous/src/Xanthous/Util/Inflection.hs
@@ -0,0 +1,14 @@
+
+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