/english_conjoin

A little Go util to print lists of strings in common English format

Primary LanguageGoMIT LicenseMIT

English ConjoinBuild Status GoDoc

A little Go util to print lists of strings in common English format

Docs

The Conjoin function takes a slice of strings and a final joiner.

Usage

package main

import (
	"fmt"
	"github.com/davidbanham/english_conjoin"
)

func main() {
	example := []string{"Alice", "Bob", "Charlie"}

	fmt.Println(english_conjoin.Conjoin(example, "and")) // Alice, Bob and Charlie
	fmt.Println(english_conjoin.Conjoin(example, "or"))  // Alice, Bob or Charlie

	dupeExample := []string{"Milk", "Flour", "Eggs", "Rice", "Flour", "Rice", "Rice"}

	fmt.Println(english_conjoin.DeDuplicate(dupeExample))  // Milk, Flour (x2), Eggs, Rice (x3)
}

There are also some helper funcs for common joiners: ConjoinAnd and ConjoinOr

There are more examples in the tests.