Skip to contents

Unwrap and call a function on a maybe value or return a default

Usage

maybe_case(.m, .f, default)

Arguments

.m

A maybe value

.f

A function to apply to the maybe value in the case of 'Just'

default

A default value to return in the case of 'Nothing'

Value

The return value of the 'Just' function or the default value

Examples

just(1:10) %>% maybe_case(mean, 0)
#> [1] 5.5
nothing() %>% maybe_case(mean, 0)
#> [1] 0