fallthrough: Fallthrough function

View source: R/optional.R

fallthroughR Documentation

Fallthrough function

Description

Permit a pattern matching to continue even if its argument is executed.

Usage

fallthrough(fun)

Arguments

fun

A result function used in make_opt()

Details

fallthrough(fun) can be applied to a result function fun inside a match_with() pattern. If there is a match, this will make the pattern matching continue through the other conditions at the end of the result function fun. match_with(variable, pattern, fallthrough(result-function), ...

Examples

library(magrittr)

a <- 4
match_with(a,
  . %>% if (. %% 2 == 0)., 
  fallthrough( function() "This number is even" ),
  . %>% if ( sqrt(.) == round(sqrt(.)) ).,  
  function() "This number is a perfect square"
)
## [1] "This number is even"   "This number is a perfect square"

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