Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple English-language string manipulation functions (e.g., PluralWord) #57

Closed
clconway opened this issue Aug 15, 2017 · 5 comments

Comments

@clconway
Copy link
Contributor

I would like to add some simple English-language output functions to this library, e.g.,

func Plural(quantity int, singular, plural string) string
//  Plural(1, "foo", "foos") ==> "1 foo"
//  Plural(2, "foo", "foos") ==> "2 foos"
//  Plural(2, "foo", "") ==> "2 foos"  (simple default pluralization)
func WordSeries(words []string, conjunction string) string
// WordSeries([]string{"foo", "bar"}, "and") ==> "foo and bar"
//  WordSeries([]string{"foo", "bar", "qux"}, "and") ==> "foo, bar and qux"

These aren't really in-scope for the current version of the library, but are broadly useful in similar situations (e.g., user/debugging output) and seem like a kind of "humanization".

I can contribute and maintain these functions if you are willing to accept a PR.

@dustin
Copy link
Owner

dustin commented Aug 16, 2017

Hmm... WordSeries seems to already be starting an Oxford comma debate. :)

@clconway
Copy link
Contributor Author

I'm happy to add OxfordWordSeries as well. ;-)

@dustin
Copy link
Owner

dustin commented Aug 29, 2017

@shurcooL Do you have any objections here? I want the Oxford comma, but it seems like a generally useful thing when dealing with sets.

@dmitshur
Copy link
Collaborator

I'm always cautious about expanding the surface area of an API and increasing scope of a library. The addition should be justified.

But, I don't have strong objections.

If the implementation is not so trivial that anyone can implement it trivially in their project, and if you think this is going to be used by enough people, then humanize will become better if this is added.

I don't have a need for this at this time, so it's hard for me to say whether it's useful.

@dmitshur
Copy link
Collaborator

Also, since @clconway offered kindly not only to contribute, but also to maintain these, that makes it easier to say yes.

clconway added a commit to clconway/go-humanize that referenced this issue Sep 15, 2017
Includes:
 - Plural and PluralWord to form simple plurals.
 - WordSeries and OxfordWordSeries to form comma-separated
   lists (e.g., "foo, bar and baz").

Fixes: dustin#57
@dustin dustin closed this as completed in #63 Nov 1, 2017
dustin pushed a commit that referenced this issue Nov 1, 2017
Includes:
 - Plural and PluralWord to form simple plurals.
 - WordSeries and OxfordWordSeries to form comma-separated
   lists (e.g., "foo, bar and baz").

Fixes: #57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants