Skip to contents

Define a property backed by one or more enum classes

Usage

property_enum(..., default = NULL)

Arguments

...

Enum classes. One or more classes from new_enum().

default

Any. Passed to S7::new_property().

Value

An S7 property typed as the union of ....

Examples

library(S7)
GridShape <- new_enum("GridShape", c("Square", "Hexagon"))
#> Overwriting method convert(<character>, <GridShape>)
Direction <- new_enum("Direction", c("North", "South"))
Board := new_class(
  properties = list(orientation = property_enum(GridShape, Direction))
)
Board(GridShape("Square"))
#> <Board>
#>  @ orientation: <GridShape>
#>  .. @ value   : chr "Square"
#>  .. @ variants: chr [1:2] "Square" "Hexagon"
#>  .. @ allow_na: logi TRUE