tests/testthat/test-maybe_flatten.R

test_that("maybe_flatten will fail with a non-maybe value", {
  for_all(
    a = anything(),
    property = function(a) maybe_flatten(a) %>% expect_error()
  )
})

test_that("maybe_flatten doesn't modify non-nested maybes", {
  nothing() %>% maybe_flatten() %>% expect_identical(nothing())

  for_all(
    a = anything(),
    property = function(a)
      just(a) %>%
        maybe_flatten() %>%
        expect_identical(just(a))
  )
})

test_that("maybe_flatten removes a layer from a nested maybe", {
  just(nothing()) %>% maybe_flatten() %>% expect_identical(nothing())

  for_all(
    a = anything(),
    property = function(a)
      just(just(a)) %>%
        maybe_flatten() %>%
        expect_identical(just(a))
  )
})

Try the maybe package in your browser

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

maybe documentation built on Aug. 7, 2023, 5:11 p.m.