Skip to content

v1.12.2

Latest
Compare
Choose a tag to compare
@ugaya40 ugaya40 released this 15 Jul 22:55
· 1 commit to main since this release
const result1 = from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).pipe(
  chunkByAccumulation(
    0,
    (acc, current) => acc + current,
    (acc) => acc <= 10
  )
).toArray();

// result1: [[1, 2, 3, 4], [5], [6], [7], [8], [9], [10]]

// Example where the first value doesn't satisfy the condition
const result2 = from([11, 1, 2, 3]).pipe(
  chunkByAccumulation(
    0,
    (acc, current) => acc + current,
    (acc) => acc <= 10
  )
).toArray();

// result2: []

// Example where enumeration stops when a single value doesn't satisfy the condition
const result3 = from([1, 2, 3, 15, 4, 5]).pipe(
  chunkByAccumulation(
    0,
    (acc, current) => acc + current,
    (acc) => acc <= 10
  )
).toArray();

// result3: [[1, 2, 3]]