sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
294 stars 23 forks source link

types: define JsSet and JsMap type constructors #281

Closed davidchambers closed 4 years ago

davidchambers commented 4 years ago

Closes #183

I set out to define $.JsWeakSet and $.JsWeakMap as well, but I decided not to do so when I learnt how strange WeakSet and WeakMap are. Users can define (nullary) types for these if necessary.

Avaq commented 4 years ago

I'm not sure why you would leave out the weak variants. Is it to discourage usage of them?

davidchambers commented 4 years ago

Weak sets can only contain objects, so the type would be JsWeakSet rather than JsWeakSet a. Similarly, weak maps can only contain objects as keys, so the type would be JsWeakMap a rather than JsWeakMap a b. The values of a weak map are not enumerable, though, so the extractor would have to be jsWeakMap => [].

These quirks deterred me, but if you think we should define $.JsWeakSet and $.JsWeakMap I will do so in a separate pull request. :)

Avaq commented 4 years ago

I see. Sounds good to me. Let's leave the weak variants to be defined by users. We can always make another PR as you said.