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

export class_inherits()? #431

Open
lawremi opened this issue Aug 31, 2024 · 4 comments
Open

export class_inherits()? #431

lawremi opened this issue Aug 31, 2024 · 4 comments

Comments

@lawremi
Copy link
Collaborator

lawremi commented Aug 31, 2024

class_inherits() is a useful utility for checking whether an object satisfies a class specification. I use the term specification, because I am not sure things like a class union or class_any are really classes (both are types of unions). But the fact that it's a specification makes it different from inherits().

Should we export it? The name seems OK. In fact, it's better than inherits(), because objects do not inherit, classes do.

We could also use something like class_satisfies() to distinguish it from inherits().

@t-kalinowski
Copy link
Member

Should we pick a different name?

Currently, we have a strong convention that symbols with a class_ prefix are things that can be used as classes in new_class(parent=), new_property(class=), inherits(what=), etc. This name would break that pattern, probably leading to confusion.

> grep("^class_", getNamespaceExports("S7"), value = T)
 [1] "class_POSIXct"     "class_environment" "class_integer"     "class_Date"       
 [5] "class_name"        "class_double"      "class_formula"     "class_POSIXlt"    
 [9] "class_missing"     "class_character"   "class_language"    "class_complex"    
[13] "class_function"    "class_list"        "class_POSIXt"      "class_vector"     
[17] "class_factor"      "class_call"        "class_array"       "class_numeric"    
[21] "class_atomic"      "class_expression"  "class_matrix"      "class_raw"        
[25] "class_logical"     "class_data.frame"  "class_any"         

@t-kalinowski

This comment was marked as off-topic.

@lawremi
Copy link
Collaborator Author

lawremi commented Oct 16, 2024

A new name would be a good idea. Perhaps just satisfies()? This could be more about meeting some general constraint, not just inheritance.

@ltuijnder
Copy link

Hi the utility function would definitely by handy if it got exported. Because you encounter it when defining your own container property where you need to test the type of child elements.
So having an easy way to check if an object satisfies a wild class definition would be great. Which is now not really possible since the class definition can take many forms.

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