Learn R Programming

matchr (version 0.1.0)

Pattern Matching and Enumerated Types in R

Description

Inspired by pattern matching and enum types in Rust and many functional programming languages, this package offers an updated version of the 'switch' function called 'Match' that accepts atomic values, functions, expressions, and enum variants. Conditions and return expressions are separated by '->' and multiple conditions can be associated with the same return expression using '|'. 'Match' also includes support for 'fallthrough'. The package also replicates the Result and Option enums from Rust.

Copy Link

Version

Install

install.packages('matchr')

Monthly Downloads

214

Version

0.1.0

License

MIT + file LICENSE

Maintainer

Chris Mann

Last Published

September 9th, 2021

Functions in matchr (0.1.0)

Match

Match Value Against Multiple Values
fallthrough

Fall Through Match
is.none

Check if Option is None
is.enum_type

Check Enum Type
is.err

Check if Result is an Err
Matchply

Match Each Object in List or Vector
is.ok

Check if Result is Ok
enum_type

Enum Type
bang

Extract Result or Return
variant

Enum Variant
into_option

Convert Object into Option
%fn%

Create Function
%.%

Compose Functions
is.enum

Is Object an Enum
is.variant

Check Enum Variant
is.some

Check if Option is Some
into_result

Convert Object into Result
match_cond

Check and Evaluate Match Condition
unwrap

Extract the Value Contained in Enum
Try

Execute Expression as Result
Result

Result
Err

Create an 'Err' Result
Some

Create an 'Some' Option
Enum

Create Enumerated Type
None

None
Option

Option
Ok

Create an 'Ok' Result