Extend Collection
Closed this issue · 3 comments
Is it possible to extend the Collection class to add my own methods.
I tried the basic way, but it appears the functions explicitly return DusanKasan\Knapsack\Collection
instances.
Hi, yes the methods/functions all return Colllection
instances so what you asking is not possible now. The implementation would require to somehow recreate the class after each operation which could be hard. Also since we don't have generics the API is impossible to write correctly.
I would recommend using the transform
method if none of the other methods are enough. Would that solve your issue?
Hi, I would like to make a question related:
Would a composition take too much effort to solve an issue like this? Would be considered a solution?
@davidmpaz I think composition would be also a solution but it requires you to wrap every method, so it will be a lot of code.