comma-and-0.2.0.0: Join text together with commas, and "and".
Maintainerhapytexeu+gh@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

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 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

Instances details
Bounded CommaStyle Source # 
Instance details

Defined in Text.Comma

Enum CommaStyle Source # 
Instance details

Defined in Text.Comma

Read CommaStyle Source # 
Instance details

Defined in Text.Comma

Show CommaStyle Source # 
Instance details

Defined in Text.Comma

Default CommaStyle Source # 
Instance details

Defined in Text.Comma

Methods

def :: CommaStyle #

Eq CommaStyle Source # 
Instance details

Defined in Text.Comma

Ord CommaStyle Source # 
Instance details

Defined in Text.Comma

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

  • commaText :: s

    The text used to join two elements together, if the second element is not the last element in the series.

  • commaAndText :: s

    The text used to join the one but last and the last element together.

Instances

Instances details
Read s => Read (CommaValues s) Source # 
Instance details

Defined in Text.Comma

Show s => Show (CommaValues s) Source # 
Instance details

Defined in Text.Comma

IsString s => Default (CommaValues s) Source # 
Instance details

Defined in Text.Comma

Methods

def :: CommaValues s #

Eq s => Eq (CommaValues s) Source # 
Instance details

Defined in Text.Comma

Ord s => Ord (CommaValues s) Source # 
Instance details

Defined in Text.Comma

toCommaValues Source #

Arguments

:: IsString s 
=> CommaStyle

The given CommaStyle to convert into the corrsponding CommaValues object.

-> CommaValues s

A CommaValues object that contains the separators for the items.

Convert the given CommaStyle to the corresponding CommaValue item.

lastJoin Source #

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"

commaAs Source #

Arguments

:: (IsString s, Monoid s, Foldable f) 
=> CommaStyle

The given CommaStyle to use.

-> f s

The Foldable of string-like elements to join.

-> s

The result that has joined the elements with commas as specified by the given CommaStyle.

Join the sequence of items with the given comma style, uses mempty as empty string if there are no items.

commaEmptyAs Source #

Arguments

:: (IsString s, Semigroup s, Foldable f) 
=> s

The item to return if the Foldable is empty.

-> CommaStyle

The given CommaStyle to use.

-> f s

The Foldable of string-like elements to join.

-> s

The result that has joined the elements with commas as specified by the given CommaStyle.

Join the sequence of items with the given comma style, uses a given "string" if there are no items.

commaWith Source #

Arguments

:: (IsString s, Monoid s, Foldable f) 
=> CommaValues s

A CommaValues object that determines the normal separator and the last separator.

-> f s

The Foldable of string-like elements to join.

-> s

The result that has joined the elements with commas as specified by the given CommaValues.

Join the sequence of items with the given CommaValues, uses mempty as empty string if there are no items.

commaEmptyWith Source #

Arguments

:: (IsString s, Semigroup s, Foldable f) 
=> s

The item to return if the Foldable is empty.

-> CommaValues s

A CommaValues object that determines the normal separator and the last separator.

-> f s

The Foldable of string-like elements to join.

-> s

The result that has joined the elements with commas as specified by the given CommaValues.

Join the sequence of items with the given CommaValues, uses a given "string" if there are no items.

comma Source #

Arguments

:: (IsString s, Monoid s, Foldable f) 
=> f s

The Foldable of string-like elements to join.

-> 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.

noComma Source #

Arguments

:: (IsString s, Monoid s, Foldable f) 
=> f s

The Foldable of string-like elements to join.

-> 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.

commaEmpty Source #

Arguments

:: (IsString s, Semigroup s, Foldable f) 
=> s

The item to return if the Foldable is empty.

-> f s

The Foldable of string-like elements to join.

-> 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.

noCommaEmpty Source #

Arguments

:: (IsString s, Semigroup s, Foldable f) 
=> s

The item to return if the Foldable is empty.

-> f s

The Foldable of string-like elements to join.

-> 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

combineWith Source #

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 Foldable of items that should be joined.

-> 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.

combineWithEmpty Source #

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 Foldable of items that should be joined.

-> 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 with a custom value if the Foldable is empty.

String-like constants

comma_ Source #

Arguments

:: IsString s 
=> s

A string-like type.

The string-like value for a comma, so ", ".

and_ Source #

Arguments

:: IsString s 
=> s

A string-like type.

The string-like value for an "and", so " and ".

commaAnd_ Source #

Arguments

:: IsString s 
=> s

A string-like type.

The string-like value for a comma and an "and", so ", and ".