Skip to contents

Constructs an iterator that maps a given function over an indefinite sequence of numeric values. The input the function f is expected to accept a single numeric argument. The sequence of arguments passed to f begin with start and are incremented by step.

Usage

itabulate(f, start = 1, step = 1)

Arguments

f

the function to apply

start

sequence's initial value

step

sequence's step size

Value

an iterator that returns the mapped values from the sequence

Examples

it <- itabulate(f=function(x) x + 1)
take(it, 4) # 2 3 4 5
#> [[1]]
#> [1] 2
#> 
#> [[2]]
#> [1] 3
#> 
#> [[3]]
#> [1] 4
#> 
#> [[4]]
#> [1] 5
#> 

it2 <- itabulate(f=function(x) x^2, start=-3)
take(it2, 6) # 9 4 1 0 1 4
#> [[1]]
#> [1] 9
#> 
#> [[2]]
#> [1] 4
#> 
#> [[3]]
#> [1] 1
#> 
#> [[4]]
#> [1] 0
#> 
#> [[5]]
#> [1] 1
#> 
#> [[6]]
#> [1] 4
#> 

it3 <- itabulate(abs, start=-5, step=2)
take(it3, 6) # 5 3 1 1 3 5
#> [[1]]
#> [1] 5
#> 
#> [[2]]
#> [1] 3
#> 
#> [[3]]
#> [1] 1
#> 
#> [[4]]
#> [1] 1
#> 
#> [[5]]
#> [1] 3
#> 
#> [[6]]
#> [1] 5
#> 

it4 <- itabulate(exp, start=6, step=-2)
take(it4, 4) # exp(c(6, 4, 2, 0))
#> [[1]]
#> [1] 403.4288
#> 
#> [[2]]
#> [1] 54.59815
#> 
#> [[3]]
#> [1] 7.389056
#> 
#> [[4]]
#> [1] 1
#>