Skip to contents

Returns an iterator dividing a value into integer chunks, such that sum(idiv(n, ...)) == floor(n)

Usage

idiv(count, ..., recycle = FALSE, chunkSize, chunks)

Arguments

count

The total

...

Unused.

recycle

Whether to restart the count after finishing.

chunkSize

the maximum size of the pieces that n should be divided into. This is useful when you know the size of the pieces that you want. If specified, then chunks should not be.

chunks

the number of pieces that n should be divided into. This is useful when you know the number of pieces that you want. If specified, then chunkSize should not be.

Value

The dividing iterator.

Details

Originally from the iterators package.

Examples


# divide the value 10 into 3 pieces
it <- idiv(10, chunks = 3)
nextOr(it)
#> [1] 4
nextOr(it)
#> [1] 3
nextOr(it)
#> [1] 3
nextOr(it, NULL)  # expect NULL
#> NULL

# divide the value 10 into pieces no larger than 3
it <- idiv(10, chunkSize = 3)
nextOr(it)
#> [1] 3
nextOr(it)
#> [1] 3
nextOr(it)
#> [1] 3
nextOr(it)
#> [1] 1
nextOr(it, NULL)  # end of iterator
#> NULL