feature: Create an Object Feature

Description Usage Arguments Value Examples

View source: R/core.R

Description

Create an Object Feature

Usage

1
feature(expr)

Arguments

expr

expression

Value

a Q7 feature

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Type1 <- type(function(num){})

hasMagic <- feature({
    change_number <- function(){
        num + 1
    }
})

myType1 <- Type1(1) %>% hasMagic()
myType1$change_number()


# Use S3 method dispatch for different behaviors
hasMagic <- feature_generic(s3 = "hasMagic")

hasMagic.Type1 <- feature({
    change_number <- function(){
        num + 1
    }
})

hasMagic.Type2 <- feature({
    change_number <- function(){
        num - 1
    }
})

Type1 <- type(function(num){},
              s3 = "Type1") %>%
    hasMagic()

Type2 <- type(function(num){},
              s3 = "Type2") %>%
    hasMagic()

myType1 <- Type1(1)
myType1$change_number()

myType2 <- Type2(1)
myType2$change_number()

Q7 documentation built on Jan. 13, 2021, 10:11 a.m.