trm_return: Flag a return value

Description Usage Arguments Value Examples

View source: R/trampoline.R

Description

Wrap a return value in your recursive function with trm_return() to have it passed along and returned by your final recursion.

Usage

1

Arguments

x

A value to be returned at the end of all recursions

Value

x with added class attribute 'trampoline_return'

Examples

1
2
3
4
5
6
7
8
trampoline(factorial(13),
           factorial = function(n) {
             if(n <= 1) {
               return(trm_return(1))
             }
             val <- yield(factorial(n - 1))
             return(val * n)
           })

trampoline documentation built on Jan. 5, 2022, 1:07 a.m.