unwrap: Extract the Value Contained in Enum

Description Usage Arguments Details Value Functions Examples

View source: R/unwrap.R

Description

Returns the value contained inside of an enum variant. The function strips all relevant attributes from the object, returning its bare value.

Usage

1
2
3
unwrap(x, ...)

unwrap_or(x, alt, ...)

Arguments

x

Enumerated value to unwrap

...

objects to be passed to methods.

alt

Alternative value to be returned in case of failure

Details

unwrap is used to extract the inside objects of an Enum. Unless the Enum was assigned a specific value, the returned value will be a list with names equal to those in the Enum declaration.

Result and Option have associated unwrap methods that automatically call an error and stop execution if the variant is either Err(e) or None, respectively. unwrap_or allows the user to specify an alternative value in case of failure on the part of Result or Option.

Value

an object of any class.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)
)

red_rgb <- unwrap(Color$Red)
blue    <- rev(red_rgb)
blue

new_err <- Err("hello world!")
unwrap_or(new_err, "this is not an error")

matchr documentation built on Sept. 9, 2021, 5:07 p.m.

Related to unwrap in matchr...