tests/testthat/test-and_then.R

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

test_that("and_then will fail with a function which doesn't return a maybe value", {
  for_all(
    a = anything(),
    property = function(a)
      just(a) %>%
        and_then(identity) %>%
        expect_error()
  )
})

test_that("and_then will not modify a maybe value with a safe identity function", {
  safe_identity <- function(a) just(identity(a))

  nothing() %>%
    and_then(safe_identity) %>%
    expect_identical(nothing())

  for_all(
    a = anything(),
    property = function(a)
      just(a) %>%
        and_then(safe_identity) %>%
        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.