Maintainer | hapytexeu+gh@gmail.com |
---|---|
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
Text.Comma
Description
This module provides functions to join elements of string-like types by adding a comma between the elements, and an "and" (optionally with a comma) between the one-but-last and the last element.
Synopsis
- data CommaStyle
- data CommaValues s = CommaValues {
- commaText :: s
- commaAndText :: s
- toCommaValues :: IsString s => CommaStyle -> CommaValues s
- lastJoin :: IsString s => CommaStyle -> s
- commaAs :: (IsString s, Monoid s, Foldable f) => CommaStyle -> f s -> s
- commaEmptyAs :: (IsString s, Semigroup s, Foldable f) => s -> CommaStyle -> f s -> s
- commaWith :: (IsString s, Monoid s, Foldable f) => CommaValues s -> f s -> s
- commaEmptyWith :: (IsString s, Semigroup s, Foldable f) => s -> CommaValues s -> f s -> s
- comma :: (IsString s, Monoid s, Foldable f) => f s -> s
- noComma :: (IsString s, Monoid s, Foldable f) => f s -> s
- commaEmpty :: (IsString s, Semigroup s, Foldable f) => s -> f s -> s
- noCommaEmpty :: (IsString s, Semigroup s, Foldable f) => s -> f s -> s
- combineWith :: (Monoid s, Foldable f) => s -> s -> f s -> s
- combineWithEmpty :: (Semigroup s, Foldable f) => s -> s -> s -> f s -> s
- comma_ :: IsString s => s
- and_ :: IsString s => s
- commaAnd_ :: IsString s => s
Data structures for text joining
data CommaStyle Source #
The two different ways to join the last two items together: with or without a comma.
Constructors
OxfordComma | The Oxford comma which uses a comma before the latest element, also known as Harvard comma or series comma. |
NoComma | The comma style where there is no comma before the "and" of the last item, informally known as the Heathen comma. |
Instances
data CommaValues s Source #
A small data type that contains the string-like values for the 'commaText, and the commaAndText
: the join between the one but last, and last element. This can be used
to define a way to comma-and in a different language.
Constructors
CommaValues | The (only) data constructor that takes values for the comma and the "comma and" to join. |
Fields
|
Instances
Arguments
:: IsString s | |
=> CommaStyle | The given |
-> CommaValues s | A |
Convert the given CommaStyle
to the corresponding CommaValue
item.
Arguments
:: IsString s | |
=> CommaStyle | The given comma style. |
-> s | A string that specifies how to join the last but one item and the last item based on the comma style. |
Specify the string that determines how to join the last but one and the last item based on the CommaStyle
.
Join with commas and "and"
Arguments
:: (IsString s, Monoid s, Foldable f) | |
=> CommaStyle | The given |
-> f s | The |
-> s | The result that has joined the elements with commas as specified by the given |
Join the sequence of items with the given comma style, uses mempty
as empty string if there are no items.
Arguments
:: (IsString s, Semigroup s, Foldable f) | |
=> s | The item to return if the |
-> CommaStyle | The given |
-> f s | The |
-> s | The result that has joined the elements with commas as specified by the given |
Join the sequence of items with the given comma style, uses a given "string" if there are no items.
Arguments
:: (IsString s, Monoid s, Foldable f) | |
=> CommaValues s | A |
-> f s | The |
-> s | The result that has joined the elements with commas as specified by the given |
Join the sequence of items with the given CommaValues
, uses mempty
as empty string if there are no items.
Arguments
:: (IsString s, Semigroup s, Foldable f) | |
=> s | The item to return if the |
-> CommaValues s | A |
-> f s | The |
-> s | The result that has joined the elements with commas as specified by the given |
Join the sequence of items with the given CommaValues
, uses a given "string" if there are no items.
Arguments
:: (IsString s, Monoid s, Foldable f) | |
=> f s | The |
-> s | The result that has joined the elements with commas and just "and" as last separator. |
Joins the sequence of items with the Oxford comma style, uses mempty
as empty string if there are no items.
Arguments
:: (IsString s, Monoid s, Foldable f) | |
=> f s | The |
-> s | The result that has joined the elements with commas, and ", and" (with comma) as last separator. |
Joins the sequence of items with the no comma style, uses mempty
as empty string if there are no items.
Arguments
:: (IsString s, Semigroup s, Foldable f) | |
=> s | The item to return if the |
-> f s | The |
-> s | The result that has joined the elements with commas and just "and" as last separator. |
Join the sequence of items with the Oxford comma style, uses a given "string" if there are no items.
Arguments
:: (IsString s, Semigroup s, Foldable f) | |
=> s | The item to return if the |
-> f s | The |
-> s | The result that has joined the elements with commas, and ", and" (with comma) as last separator. |
Join the sequence of items with the no comma style, uses a given "string" if there are no items.
Basic joining of elements
Arguments
:: (Monoid s, Foldable f) | |
=> s | The comma item placed between each item and the next, except for the last join. |
-> s | The item used to join the one but last item and the last item. |
-> f s | The |
-> s | The item generated by joining the elements with the comma and last join item. |
Join the Foldable
of elements with a given item for a comma and for the last join.
Arguments
:: (Semigroup s, Foldable f) | |
=> s | The item used if the foldable item is empty. |
-> s | The comma item placed between each item and the next, except for the last join. |
-> s | The item used to join the one but last item and the last item. |
-> f s | The |
-> s | The item generated by joining the elements with the comma and last join item. |
String-like constants
Arguments
:: IsString s | |
=> s | A string-like type. |
The string-like value for a comma, so ", "
.
Arguments
:: IsString s | |
=> s | A string-like type. |
The string-like value for an "and", so " and "
.