# NOT RUN {
### Create a Linked List
# Node is an enum with two varieties: a link to the next node, and none
# 'Node$Some' is a function that accepts two values and generates the enum
# variant, while 'Node$Empty' is a variant
Node <- Enum(
Some(Val, Next),
Empty
)
# Initialize an empty linked list, push values to the front
new_list <- Node$Empty
new_list <- Node$Some(1, new_list)
new_list <- Node$Some(2, new_list)
new_list
# return the head of the list ('car') and tail ('cdr')
car <- new_list$Val
cdr <- new_list$Next
### RGB Colors
# The Color enum is provided with a named type "Color". All
# variants will have both "Enum" and "Color" as a class.
# Each variant is associated with a specific value.
Color <- Enum(
"Color",
Black = c(0,0,0),
Red = c(255,0,0),
Green = c(0, 255, 0),
Blue = c(0, 0, 255),
White = c(255, 255, 255)
)
Color$Red
# This will generate an error since it is not a function
# Color$Black()
### Directions
# This enum creates a sequence of numbers associated with
# a particular direction. Enum automatically increments the
# values if the initial variant is assigned a single number
Direction <- Enum(
North = 1,
East,
South,
West
)
# This will result in '5' since North is '1' and West is '4'
Direction$North + Direction$West
# }
Run the code above in your browser using DataLab