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

Normative Conventions: pretend primitives aren't iterable #152

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
all primitives now
  • Loading branch information
michaelficarra committed Jul 23, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 811705a9ac3717615d7275cf4e6933f452532e42
6 changes: 3 additions & 3 deletions normative-conventions.md
Original file line number Diff line number Diff line change
@@ -38,10 +38,10 @@ Some APIs intentionally round non-integral inputs, for example as an attempt to

NB: This convention is new as of 2024, and most earlier parts of the language do not follow it.

## Reject primitive Strings in iterable-taking APIs and syntax
## Reject primitives in iterable-taking positions

Any time an iterable value (a value that has a `Symbol.iterator` method) is expected, primitive Strings should be treated as if they were not iterable. Usually, this will mean throwing a `TypeError`. String Objects, however, should be treated like any other Object.
Any time an iterable value (a value that has a `Symbol.iterator` method) is expected, primitives should be treated as if they were not iterable. Usually, this will mean throwing a `TypeError`. Primitive wrapper Objects such as String Objects, however, should be treated like any other Object.

Although primitive Strings are iterable (`String.prototype` has a `Symbol.iterator` method which enumerates code points), it is now considered a mistake to iterate a String without specifying whether the String is providing an abstraction over code units, code points, grapheme clusters, or something else.
Although primitive Strings are default iterable (`String.prototype` has a `Symbol.iterator` method which enumerates code points), it is now considered a mistake to iterate a String without specifying whether the String is providing an abstraction over code units, code points, grapheme clusters, or something else.

NB: This convention is new as of 2024, and most earlier parts of the language do not follow it.