unwrap {matchr}R Documentation

Extract the Value Contained in Enum

Description

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

Usage

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

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")


[Package matchr version 0.1.0 Index]