knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(emitters)

R functionals

lapply/map

stream <- ReadableStream$new(list("1", "2", "3", "4", "5")) %|>%
  map_stream(function(data) {
    as.numeric(data)
  })

stream$on("data", print)

filter

stream <- ReadableStream$new(1:1000) %|>%
  filter_stream(function(data) {
    data > 500
  })

stream$on("data", print)

reduce

stream <- ReadableStream$new(1:1000) %|>%
  reduce_stream(
    function(x, y) {
      sum(x, as.numeric(y))
    },
    base_value = 0
  )

stream$on("data", print)

other functionals

stream <- ReadableStream$new(list("ABC", "AB", "ABB")) %|>%
  split_stream("B")

stream$on("data", print)


ElianHugh/emitters documentation built on Feb. 6, 2022, 4:55 a.m.