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 frozen collections #5

Merged
merged 6 commits into from
May 14, 2022
Merged

Add frozen collections #5

merged 6 commits into from
May 14, 2022

Conversation

rekmarks
Copy link
Member

@rekmarks rekmarks commented May 6, 2022

Add FrozenMap and FrozenSet, which are like their Readonly counterparts except it is actually impossible to modify them.

@rekmarks rekmarks changed the base branch from main to initial-implementation May 6, 2022 19:25
@rekmarks
Copy link
Member Author

rekmarks commented May 7, 2022

The current implementation is broken because some collection methods (such as forEach) provide a reference to the underlying collection, and these methods aren't yet implemented properly.

Edit: This issue has been resolved.

Base automatically changed from initial-implementation to main May 12, 2022 21:19
@rekmarks rekmarks marked this pull request as ready for review May 12, 2022 21:22
@rekmarks rekmarks requested a review from a team as a code owner May 12, 2022 21:22
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits, but looks good regardless.

return this.#map[Symbol.iterator]();
}

constructor(entries?: readonly (readonly [Key, Value])[] | null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the double readonly? Just curious.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about putting the constructor above get size and the iterator method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On mobile right now, but IIRC readonly isn't recursive, so the double was necessary.

Regarding the place of getters etc., we've been putting properties before the construction by convention (or necessity?), and getters seem more conceptually similar to properties than methods. Class "item" (what's the word for properties and methods?) order is not something we've ever standardized, although it would be cool if we had a lint rule that imposed some kind of order.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty agnostic about where the properties go, but I merged this so as to not lost the approvals. Maybe we can create an issue on the lint config?

return this.#set[Symbol.iterator]();
}

constructor(values?: readonly Value[] | null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about putting this at the top of the class?

@rekmarks rekmarks merged commit cb44f74 into main May 14, 2022
@rekmarks rekmarks deleted the frozen-collections branch May 14, 2022 19:54
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

Successfully merging this pull request may close these issues.

3 participants