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

Convenience API suggestion: return an array #1

Closed
domenic opened this issue Sep 28, 2016 · 8 comments
Closed

Convenience API suggestion: return an array #1

domenic opened this issue Sep 28, 2016 · 8 comments

Comments

@domenic
Copy link
Member

domenic commented Sep 28, 2016

E.g. Intl.Segmenter.segments("string", "fr", { type: "word" })

@mathiasbynens
Copy link
Member

mathiasbynens commented Sep 29, 2016

Shouldn’t this be an iterator so it can be done lazily? If you really need an array you could then use the spread operator.

@domenic
Copy link
Member Author

domenic commented Sep 29, 2016

The main API in the readme returns an iterator. The point of this convenience API is for when you know you need all the results.

@mathiasbynens
Copy link
Member

Apologies; I had somehow interpreted your suggestion as “an array of strings: one for each segment”.

@domenic
Copy link
Member Author

domenic commented Sep 29, 2016

I guess I was ambiguous. Now that you mention it, as a convenience API, that sounds better to me.

@mathiasbynens
Copy link
Member

mathiasbynens commented Sep 30, 2016

#4 is similar.

@littledan
Copy link
Member

If we want something like this, maybe it should be a method on a Segmenter instance, e.g.,

new Intl.Segmenter("fr", {type: "word"}).segmentToArray("string"))

What should be the output exactly? Would you want just the words in this case, ignoring the whitespace and punctuation segments?

@domenic
Copy link
Member Author

domenic commented Oct 18, 2016

Yeah, just the words is what I was assuming.

A static method feels more convenient than newing up a new object, but I guess Intl has not gone with that style so far.

@domenic
Copy link
Member Author

domenic commented Mar 16, 2017

Closing since it doesn't fit with the style of Intl.

@domenic domenic closed this as completed Mar 16, 2017
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