scratch/stream_util.R

accumulate <- function(ch) { force(ch)
  stream({
    total <- 0
    repeat yield(total <- total + awaitNextOr(ch, break))
  })
}

total <- function(ch) { force(ch)
  async({
    total <- 0
    for (i in ch) total <- total + i
    total
  })
}
crowding/generators documentation built on June 28, 2023, 6:14 a.m.