zatonovo/lambda.r

typeclass and multiple deriving

hs3180 opened this issue · 4 comments

typeclass and deriving are very useful for composing interfaces.
and it should be easy mapping typeclass to S3 class in R.

ClassA(x) %as% x
ClassB(x) %as% x
MyClass(x) %as% {
    ClassB(ClassA(x))
}

with magrittr, it may be more clear.

ClassA(x) %as% x
ClassB(x) %as% x
MyClass(x) %as% {
    ClassA(x) %>% ClassB
}

That's up to you if you want to use the pipe within your type constructor. Let me know if it doesn't work.

you are right. pipe breaks lazy evaluation, following code may be better with functional package.

ClassA(x) %as% x
ClassB(x) %as% x
MyClass(x) %as% {
  Compose(ClassA, ClassB)(x)
}