divnix / POP

Pure Object Prototypes
MIT License
20 stars 1 forks source link

feat: pops can be extended through their functor #7

Closed Pacman99 closed 1 year ago

Pacman99 commented 2 years ago

This makes pops work similarly to jsonnet objects. Extending a pop is much easier. You just call the pop with the attribute set to extend it with.

The __functor I added has some magic, where it can detect if you just pass it an attrset, a function with one argument, or two arguments and pass arguments appropriately. I think this makes the process of updating pops more elegant. Without it though, I think we could just force the argument passed to the functor be an Extension.

p = pop { defaults.a = 0; }
p { a = 1; }
p (self: { a = 1; b = self.b; })
p (self: super: { a = super.a + 1; b = self.a; })