# Type constraints are optional and include the return type
reciprocal(x) %::% numeric : numeric
reciprocal(x) %when% {
# Guard statements can be added in succession
x != 0
} %as% {
# The function body follows
1 / x
}
reciprocal(x) %::% character : numeric
reciprocal(x) %as% {
reciprocal(as.numeric(x))
}
seal(reciprocal)
describe(reciprocal, 2)
Run the code above in your browser using DataLab