RConsortium / S7

S7: a new OO system for R
https://rconsortium.github.io/S7
Other
399 stars 33 forks source link

Add class lookup table #461

Closed t-kalinowski closed 1 week ago

t-kalinowski commented 2 weeks ago

This PR enables usage of the base constructors like base::character in new_class(), new_property(), and similar.

For example:

library(S7)
Foo <- new_class("foo", parent = character)

Foo
#> <foo> class
#> @ parent     : <character>
#> @ constructor: function(.data) {...}
#> @ validator  : <NULL>
#> @ properties :
Foo()
#> <foo> chr(0)
lawremi commented 1 week ago

What is the rationale? We had considered this early on, since classes are constructors, but we went with reified class objects instead. I'm not sure about having both.

t-kalinowski commented 1 week ago

classes are constructors

The consistency of this is enticing. Also, less typing.

One downside is that | wouldn't dispatch to new_union(), so usage would have to be as_class(character) | numeric or new_union(character, numeric)