snix/src/Xanthous/Util/Inflection.hs
Griffin Smith ecd33e0c90 Add ViewPatterns to default-extensions
Seems relatively harmless
2020-05-11 23:03:11 -04:00

14 lines
336 B
Haskell

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