Skip to content

Commit

Permalink
separate are_blocks_compatible()
Browse files Browse the repository at this point in the history
  • Loading branch information
nbenn committed Nov 12, 2024
1 parent f351163 commit afacf11
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions R/registry.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,21 @@ construct_block <- function(block, ...) {
block(...)
}

are_blocks_compatible <- function(x, y) {

stopifnot(inherits(x, "block_descr"))

tryCatch(
{
attr(x, "input")(x(), y)
TRUE
},
input_failure = function(e) {
structure(FALSE, msg = conditionMessage(e))
}
)
}

#' Find stack compatible blocks
#'
#' Given a stack, we use the registry to find
Expand All @@ -272,22 +287,12 @@ construct_block <- function(block, ...) {
#' @export
get_compatible_blocks <- function(stack) {

is_compat <- function(x, y) {
tryCatch(
{
attr(x, "input")(x(), y)
TRUE
},
input_failure = function(e) FALSE
)
}

if (length(stack)) {
dat <- block_output_ptype(stack[[length(stack)]])
} else {
dat <- NULL
}

blocks <- available_blocks()
blocks[lgl_ply(blocks, is_compat, dat)]
blocks[lgl_ply(blocks, are_blocks_compatible, dat)]
}

0 comments on commit afacf11

Please sign in to comment.