R/i_concat.R

Defines functions i_concat

Documented in i_concat

#' @rdname i_chain
#' @param obj an iterable.
#' @description `i_concat(obj)` takes an iterable that returns
#'   iterables, and chains together all inner values of iterables into
#'   one iterator. Analogous to `unlist(recursive=FALSE)`.
#' @export
i_concat <- function(obj, ...) {
  obj <- iteror(obj, ...)
  current <- NULL

  nextOr_ <- function(or) {
    if (is.null(current)) {
      current <<- iteror(obj(or = return(or)))
    }
    repeat {
      return(current(or = {
        current <<- iteror(obj(or = return(or)))
        next
      }))
    }
  }

  iteror_internal(nextOr_)
}

Try the iterors package in your browser

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

iterors documentation built on May 31, 2023, 5:36 p.m.