A little Go util to print lists of strings in common English format
The Conjoin function takes a slice of strings and a final joiner.
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.