inst/doc/maybe-monad.R

## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(chronicler)
library(maybe)

## -----------------------------------------------------------------------------
m_sqrt <- maybe(sqrt)

m_sqrt(16)

## -----------------------------------------------------------------------------
m_sqrt("10")

## -----------------------------------------------------------------------------
r_sqrt <- record(sqrt)

r_sqrt("16")

## -----------------------------------------------------------------------------
r_sqrt <- record(sqrt)

r_sqrt(16)

## -----------------------------------------------------------------------------
pick(r_sqrt(16), "value")

## -----------------------------------------------------------------------------
(r_sqrt(16))$value

Try the chronicler package in your browser

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

chronicler documentation built on June 22, 2024, 11:30 a.m.