Learn R Programming

eventr (version 1.0.0)

handler: Handler Constructor

Description

Construct a handler object.

Usage

handler(type, FUN)

new_handler(type, FUN)

validate_handler(type, FUN)

Arguments

type

A character string indicating the event type to handle.

FUN

A function which use an obj and an event as input parameters and returns an object as output.

Value

The handler() function returns an object of type handler. A handler object contains two elements: type and FUN. Type is a string indicating the type of event and FUN is a R function with to params: obj and event. obj is any R object and event is an event object returned by the event() function.

Examples

Run this code
# NOT RUN {
set_birth_date <- function(obj, event){
  obj$birthDate <- event$body$birthDate
  return(obj)
}

set_death_date <- function(obj, event){
  obj$deathDate <- event$body$deathDate
  return(obj)
}

birth_handler <- handler(type = 'BIRTH', FUN = set_birth_date)
birth_handler

death_handler <- handler(type = 'DEATH', FUN = set_death_date)
death_handler

# }

Run the code above in your browser using DataLab