Skip to content

Commit

Permalink
remove unnecessary if else blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHWade committed Aug 15, 2024
1 parent e95c169 commit 17268d8
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions R/funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,15 @@
#' between(x, "b", "c", ptype = x)
between <- function(x, left, right, ..., ptype = NULL) {
check_dots_empty0(...)
if (is.null(ptype)) {
args <- list(x = x, left = left, right = right)
# Common type of all inputs
args <- vec_cast_common(!!!args, .to = ptype)
x <- args$x
args$x <- NULL
} else {
# Cast left and right to the type of ptype
left <- vec_cast(left, ptype)
right <- vec_cast(right, ptype)
# Ensure x is also of type ptype
x <- vec_cast(x, ptype)
}

# But recycle to size of `x`
args <- vec_recycle_common(left = left, right = right, .size = vec_size(x))
args <- list(x = x, left = left, right = right)
# Common type of all inputs
args <- vec_cast_common(!!!args, .to = ptype)
x <- args$x
args$x <- NULL

# Recycle to size of `x`
args <- vec_recycle_common(!!!args, .size = vec_size(x))
left <- args$left
right <- args$right

Expand Down

0 comments on commit 17268d8

Please sign in to comment.