diff options
author | Griffin Smith <root@gws.fyi> | 2019-09-20T23·38-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-09-20T23·38-0400 |
commit | dd1616666593f65bab70f1363b5d040fe5edd054 (patch) | |
tree | 4009c7004ad2becd2b316c9212a8c778a8c646ce /src/Xanthous/Util/Inflection.hs | |
parent | 4db3a68efec079bdb8723f377929bfa05860bdc2 (diff) |
Describe what you see when you walk over items
Every step the character takes, describe the entities at that position excluding the character.
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 |