Just: Represent values that exist.

Description Usage Arguments Format Details Value See Also Examples

Description

One of the choice types for a Maybe monad (the other being Nothing)

Usage

1
Just(a)

Arguments

a

A value of any non-null type

Format

Just :: a -> Maybe a

Details

Based off the Maybe monad in Haskell and Elm but similar in construction to the result "monad" supplied by purrr::safely(). A Maybe monad is a choice type: it is either Just(a_value) or it is Nothing(). It can be used to document optional arguments, force proper error handling, and deal with lists/records with optional entries. It can be useful if you have a value that is only filled in sometimes. Or if a function takes a value sometimes, but does not absolutely need it. Or if a function would otherwise return a NULL. The Maybe type reminds users of your code to remember to handle both possible states: when the value exists and when it does not.

Value

An Maybe type (a wrapper around the original value of type 'a')

See Also

Other Maybe type: Nothing

Examples

1
2
3
4
5
6
7
safer_division <- function(x, y) { if (y == 0) { Nothing() } else { Just(x / y) } }
safer_division(1, 2) # Just(0.5)
safer_division(1, 0) # Nothing()

## Not run: safer_division(1, NULL)
# Runtime error:
# ... argument is of length zero

Teresa00/hfmAnnotation documentation built on May 14, 2019, 12:51 a.m.