fwalk: Walk over a vector or list with side effects

View source: R/fwalk.R

fwalkR Documentation

Walk over a vector or list with side effects

Description

Applies a function '.f' to each element of '.x', typically for its side effects (e.g., printing, writing files). This function is the side-effect-friendly equivalent of 'fmap()'. Supports parallel execution and progress bar display.

Usage

fwalk(.x, .f, ncores = NULL, pb = FALSE, ...)

Arguments

.x

A list or atomic vector of elements to iterate over.

.f

A function to apply to each element of '.x'. Should be called primarily for side effects.

ncores

Integer. Number of cores to use for parallel processing. Default is 'NULL' (sequential).

pb

Logical. Whether to show a progress bar. Default is 'FALSE'.

...

Additional arguments passed to '.f'.

Value

Invisibly returns '.x', like 'purrr::walk()'.

Examples

# Print each element
fwalk(1:3, print)

# Simulate writing files in parallel

fwalk(1:3, function(i) {
  cat(paste("Processing item", i, "\n"))
  Sys.sleep(0.5)
}, ncores = 2, pb = TRUE)



functionals documentation built on Aug. 8, 2025, 7:32 p.m.