Skip to content

Golang library which provides functions for joining lists into natural language strings.

License

Notifications You must be signed in to change notification settings

oalders/go-joined

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

joined

Provides functions for joining lists into natural language strings.

Functions

func And

func And(list []string) string

And joins the last 2 elements of a list with " and ", while joining preceding elements with a comma.

list := []string{"one", "two"}
fmt.Println(And(list)) // "one and two"

list = []string{"one", "two", "three"}
fmt.Println(And(list)) // "one, two and three"

func Arbitrary(wordSeparator string, conjunction string, list []string) string

Arbitrary joins the last 2 elements of a list with the supplied conjunction, while joining preceding elements with the supplied word separator. Note that you'll need to provide your own padding for both the word separator and the conjunction.

list := []string{"eins", "zwei", "drei"}
fmt.Println(Arbitrary(", ", " und ", list)) // "eins, zwei und drei"

func Or

func Or(list []string) string

Or joins the last 2 elements of a list with " or ", while joining preceding elements with a comma.

list := []string{"one", "two"}
fmt.Println(Or(list)) // "one or two"

list = []string{"one", "two", "three"}
fmt.Println(Or(list)) // "one, two or three"

Readme created from Go doc with goreadme

About

Golang library which provides functions for joining lists into natural language strings.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages