Skip to content

Commit

Permalink
feat: add as_callbacks.NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Apr 25, 2024
1 parent e31044c commit 19835f8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

S3method(as.data.table,Dictionary)
S3method(as_callback,Callback)
S3method(as_callbacks,"NULL")
S3method(as_callbacks,Callback)
S3method(as_callbacks,list)
S3method(discard,data.frame)
Expand Down
12 changes: 9 additions & 3 deletions R/Callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ as_callbacks = function(x, clone = FALSE, ...) { # nolint
UseMethod("as_callbacks")
}

#' @rdname as_callback
#' @export
as_callbacks.NULL = function(x, ...) { # nolint
list()
}

#' @rdname as_callback
#' @export
as_callbacks.list = function(x, clone = FALSE, ...) { # nolint
Expand Down Expand Up @@ -221,7 +227,8 @@ clbks = function(.keys) {
#'
#' @return [Callback] | List of [Callback]s.
#' @export
assert_callback = function(callback) {
assert_callback = function(callback, null_ok = FALSE) {
if (null_ok && is.null(callback)) return(invisible(NULL))
assert_class(callback, "Callback")
invisible(callback)
}
Expand All @@ -230,6 +237,5 @@ assert_callback = function(callback) {
#' @param callbacks (list of [Callback]).
#' @rdname assert_callback
assert_callbacks = function(callbacks) {
assert_list(callbacks)
if (length(callbacks)) invisible(lapply(callbacks, assert_callback)) else invisible(NULL)
invisible(lapply(callbacks, assert_callback))
}
3 changes: 3 additions & 0 deletions man/as_callback.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/assert_callback.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19835f8

Please sign in to comment.