inst/doc/UserGuide.R

## ----include = FALSE----------------------------------------------------------
library(optional)

## -----------------------------------------------------------------------------
a <- option(5)
class(a)

## -----------------------------------------------------------------------------
a == 5
a

## -----------------------------------------------------------------------------
a <- option(5)
some(a)
a <- none
some(a)

## -----------------------------------------------------------------------------
c_opt <- make_opt(c)
c_opt(option(2), none, option(5))
c_opt()

## -----------------------------------------------------------------------------
library(magrittr)

a <- 5
match_with(a,
  . %>% option(.),          paste,
  none,                   function() "Error!"
)

## -----------------------------------------------------------------------------
a <- 4
match_with(a,
  1,                 function() "Matched exact value",
  list(2, 3, 4),     fallthrough(function() "Matched in list"),
  . %>% if (. > 3)., function(x) paste0("Matched in condition: ",x,">3")
)

Try the optional package in your browser

Any scripts or data that you put into this service are public.

optional documentation built on April 28, 2022, 1:07 a.m.