about summary refs log tree commit diff
path: root/src/Xanthous/Util/Inflection.hs
blob: fc66c0876125eb551b27925535c8c481e2ef36b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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